I want to send notifications to all the android devices within my app. Actually, I can send a notification to a single token and it looks like this:
{
"to": "dwh6BFzxAOE:APA91bFenA-tySAKuNtiJGCeULewqYOwRDwfZMe4hWGN10Gx2S3sEoArZOvn_0pQihsDOtx6upcmwBbrTT2gG-rpYmPmXOvuzqMRoZy_rM6xCPyviXIn-JAAtoEEq2S4wEtGgnOBLR41",
"notification": {
"title": "My title",
"body": "This is the message"
}
}
But I don't understand how to send this notification to all devices at once. Without subscription.
I am using flutter for the apps, and I have created a react js web service to call this API REST and POST notifications.
To achieve Push Notifications via Firebase, you need to implement FireBase Cloud Messaging to push notifications to devices.
From the docs,
An FCM implementation includes two main components for sending and receiving:
A trusted environment such as Cloud Functions for Firebase or an app server on which to build, target, and send messages.
An iOS, Android, or web (JavaScript) client app that receives messages via the corresponding platform-specific transport service.
See the documentation for server setup, or you can also use FireBase Functions. It sounds like you want to integrate Firebase Functions with Cloud Messaging. I haven't done this before, but here is a blog post doing this for a Flutter Web project:
https://medium.com/#umeshnalinde7/flutter-cloud-messaging-with-firebase-functions-firestore-android-175904a15537
Related
I have created a Azure Notification hub namespace, I'm trying to configure the Google FCM section of it by entering the API Key, but when I do that it is giving me this error
Error updating notification hub
{"error":{"code":"BadRequest","message":"Invalid Firebase credentials."}}
The Key I added it from the google-services.json file
But when I send a notification from FCM console, I'm able to send it and receive the notification.
Any inputs would be appreciated
Azure Notification Hub doesn't support FCM (yet) but GCM as I'm writing those lines.
You need to mention the server key available under your Firebase project settings in the Cloud Messaging tab. You should see something like this:
The key that you want to mention in Azure Notifications Hub is the purple one.
If Cloud Messaging API (Legacy) is disabled (which should be the case by default since it's deprecated), just hit the 3 vertical dots on the right and navigate to the only available menu "Manage API in Google Cloud Console". And just enable it :)
Most tutorials I've seen on the topic of notifications either broadcast notifications through the Firebase Console, or create in-app notifications that don't work if the app is in the background or is closed completely.
Is there a way to make notifications pop up dynamically using Flutter and Firebase even when the app is closed? Something like Whatsapp or Instagram notifications.
Reference image for what I mean by notifications like Whatsapp: https://www.techidence.com/wp-content/uploads/2020/10/WhatsApp-Nootifications.jpg
You won't be able to generate dynamic notifications directly from Flutter. Since to do this, the App has to be active. Usually you would send these kind of notifications from some kind of backend. Google Cloud Messaging exposes an API for this, which allows you to send POST requests to an Endpoint, and Google handles the sending of the actual notification.
Check this article under the point "1. Send Notification"
https://medium.com/#selvaganesh93/firebase-cloud-messaging-important-rest-apis-be79260022b5
I want to show notification in my app even if the app is closed.. I don't need Firebase's Push Notification Service. The idea is similar to WhatsApp's message notification service.
When a value is added to firebase by a user another user should receive notification that there is a value change
Can someone tell me how this is done and What should I use to achieve this?
Push notifications for all major apps run through APNS for iOS, and Firebase Cloud Messaging for Android. While the apps may use a higher-level service from their application code, those services depend on APNS and FCM for the actual message delivery.
To see an example of how to build a notification system on top of this, based on values being written to a database, see Send Firebase Cloud Messaging notifications for new followers.
I want to create my own push notification mechanism for my own iOS applications.
I compared some services like pushy.me or Google Firebase. I think Pushy is the only service that can push notifications independent from Apple APNs, but it uses simple HTTP long-poll requests to receive notifications (in the iOS SDK).
But how does Firebase work? Does it still depend on Apple's APNs? How will it affect my battery life?
Firebase Cloud Messaging (FCM) delivers push notification to iOS devices via Apple's Push Notifications service. Also FCM extends functionality of push notifications.
How FCM extends?
FCM works with iOS and Android. Cool feature if you have the app for both platforms;
Don't need to develop backend for sending notifications, storing pn tokens etc. Just register your app in the Google Developer Console and follow User Guides. For sending a push just execute request to https://fcm.googleapis.com/fcm/send with params;
Broadcast notifications. The app subscribes to a topic and then you can send a notification to all topic subscribers. Very cool;
Upstream messages (send data to the server)
Also Google has others services you can extend FCM with. For example Cloud Functions.
I didn't find that FCM integration take big affect to battery life in my apps.
UPDATE:
FCM framework sends push notification token (and other info) to Google services. Also as I mentioned above you can subscribe app for a specific topic. Than Google knows which device needs to send a push to.
There is a possibility to setup FCM in iOS automatically(with using method swizzling). FCM exchange AppDelegate methods and knows your's device pn token.
Firebase Cloud Messaging (FCM) utilizes APNs (Apple push notifications services) for delivering the messages to iOS devices.
So basically, FCM wraps iOS methods like registerForRemoteNotifications or didReceiveRemoteNotification using method swizzling (BTW, you can disable this if you wish, although I can't see any reason...).
On the technical side - the phone is keeping an open connection with APNs and this tunnel is used for sending the messages themselves.
My setup include a webapp, a backend server and an android app.
I want to be able to chat between my android app and webapp.
Init:
Android app has subscribed to the topic /topics/chatGroupName
Similarly on browser, I get the registrationToken and send it to my server where I use code similar in https://github.com/ToothlessGear/node-gcm/pull/211/files (addToTopicNoRetry) to subscribe the browser to the topic: /topics/chatGroupName
When I send a message from the web, I use my backend server to send a GCM message on a topic like /topics/chatGroupName and the android app receives this message.
But when I send GCM message from Android app on this topic /topics/chatGroupName, I dont get any notification on the browser app.
Even my https://iid.googleapis.com/iid/info/REGISTRATION_TOKEN?details=true shows that this registration token has already subscribed to /topics/chatGroupName
Firebase has now released javascript library that supports FCM push notifications with support for topics.
Ref: https://firebase.google.com/docs/cloud-messaging/js/client