I would like to get the registrationID from my app. Does the registrationid exist before your app gets sent to the store ? If it doesn't how to I test push notifications ?
The device registration token that FCM uses to deliver messages for your app to a device is created when an app with the Firebase Cloud Messaging SDK is installed on that device. Your app does not need to be in the Play store for that to happen. See the documentation on accessing the registration token to learn how to get that token in your application code.
The easiest way to test delivery is to send a notification through the Firebase console, in which case you only need the FCM registration token or a topic (that your application code is subscribing to).
To send a message to the device from (server-side) code, you need the FCM token (or topic again), the FCM server key (or OAuth authorization), and the sender ID.
Related
Please note that this question is not about getting device token on client side.
I am very new to react-native and firebase and I want to implement push notication service of FCM. What I am planning to do is to send a notification to particular device using its device token on my nodejs app server or cloud function( not through console). But as I have found, FCM doesn't provides any API to accrss token by username. Suppose I want to send notification to user X( for the time being, suppose that one user signs only on single device). Now using the function sendToDevice(), I can send the message to a specific device. But how would I know the device token of user X. Do I need to store tokens in the firebase database by myself? Or can I get along without storing FCM tokens?
Please guide me because firebase docs aren't clear about this.
Save the device token for a particular user in DB and then you can use fcm-node npm in which there is a simple function to send a push to a particular device token.
You also need to use the FCM server key which you will get easily on the firebase console.
FCM doesn't offer a way to associate device tokens to individual users who might be using your app from multiple devices. You will need to write code to associate a device token to a user account by sending that token to your backend, along with the user's ID. Only then can you collect FCM tokens for that user, and message them on any of their devices.
I am trying to build a wrapper app with cordova and using PHP as server backend.
I am using cordova-plugin-fcm to handle push notification.
Correct me if I am wrong, each device (android and ios) has own id which is used to send notification.
How can I get that id and send it to PHP route so that I can bind it with the logged in user and send notification?
//FCMPlugin.onTokenRefresh( onTokenRefreshCallback(token) );
//Note that this callback will be fired everytime a new token is generated, including the first time.
FCMPlugin.onTokenRefresh(function(token){
alert( token );
});
In above example token is the id to be send to PHP to send notification?
Can the device.uuid used for sending notification?
I have already setup my Firebase configuration and the project has google-services.json and GoogleService-Info.plist in place.
Thank you
Firebase Cloud Messaging targets its messages at a specific app on a specific device. Each specific app install is identified by Firebase's Instance ID, also referred to as a device registration token, or an FCM token.
The Firebase documentation on accessing the registration token says this about it:
On initial startup of your app, the FCM SDK generates a registration token for the client app instance. If you want to target single devices or create device groups, you'll need to access this token by extending FirebaseMessagingService and overriding onNewToken.
From a quick read through the Cordova documentation on device.uuid, this seems to merely identify the device, and not the app on the device. Since FCM messages are delivered to a specific app on each device, it seems unlikely you can use the UUID of the device as a replacement.
Even if the UUID is unique for each app on each device, it won't be a drop-in replacement, as FCM only works with its own registration tokens. At the very least you'll need to keep a mapping of the device.uuid values to their corresponding FCM token.
The document from Google says:
GCM tokens retrieved via GoogleCloudMessaging.register() or
InstanceID.getToken() will continue to work in FCM without any
modification or renewal.
But when I update my APP to FCM. The old GCM token which stores in my Server does not work anymore. When I tried to send a push message, the Google Message server response the error message, not registered. Does anyone ran into the same problem?
Based from the documentation of GCM and FCM FAQ:
Will your existing GCM tokens and token handling still work?
Your GCM and FCM registration tokens are mutually interchangeable; you
can send to existing GCM tokens through the FCM HTTP server APIs. For
GCM and FCM token handling, remember:
If you store and send to specific tokens, be sure to implement the token refresh method to ensure your tokens are always up to date
iOS devs should avoid calling .getToken(authorizedEntity,scope) unless there is a need to enable multiple senders. Use
FirebaseInstanceId.getInstance().getToken() instead.
Am setting up push notifications for my Android App. The App is not published into Google Play Store yet. Am testing this app by installing APK directly on my mobile.
Can FCM (Firebase Cloud Messaging Server) send notifications to mobile phones which has done installation from APK files directly (not through playstore)?
Just want to know how FCM will work in this case?
YES. FCM can send notifications to your app as long as your device is registered to receive messages with FCM server
On initial startup of your app, the FCM SDK generates a registration token for the client app instance. FCM Server will manage the registration token and use this token to identify your device and send notifications. Note that the registration token can be changed in some case View more here
You can test by sending notifications to your device from Notification Composer. Select target is Single Device and your registration token is target device.
// Get the current registration token
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
To handle message follow the document
Yes you can do by using Firebase console
In firebase console select Function tab which is present in left part of firebase console.
Download node.js in your system and code it according to your wish in node.js.
Firebase token should be mention in your java code.
We are developing apps both in IOS and Android. GCM push notification has been enabled for IOS and its working fine now. The package name for both the platforms are going to be the same.
I was given SERVER API KEY and SENDER ID by ios developer to set up gcm for android. While looking for the steps, I came across https://developers.google.com/cloud-messaging/android/client.
I kept to myself that the steps listed in the contents need to be done to set up GCM for android (please correct me if I am wrong).
Get Config file and add it to Android project
Set up Google play services (I added gcm in my project dependency)
Add entries to Manifest file
Check for google play services APK
Obtain registration token.
"An Android application needs to register with GCM connection servers before it can receive messages"
"The client app should store a boolean value indicating whether the registration token has been sent to the server." - My backend team told me I dont need to send them anything I have to just configure gcm in the app and the app will receive messages from backend.
So, My question is Do I need to have RegistrationIntentService and MyInstanceIDListenerService. Also, Do I have to define my InstanceIDListenerService in Manifest?
Our backend uses device id to send push notifications to devices so they dont need registration token to be sent to them as we send device id. So in this case, Should I register my app with GCM using RegistrationIntentService and InstanceIDListenerService? if so, should the app keep the registration token with itself. Is this registration needed?
GCM supports three types of downstream (server-to-client) messaging: send to a specific device (also called "simple" or "targeted"), send to a topic, or send to a device group. Your question says, "our backend uses device id to send push notifications to devices". It is not clear what "device ID" is and which type of messaging you intend to use. Your backend team has told you that you "don't need to send them anything". If that is true, I don't know where they are getting the "device ID".
Each of the three types of messaging provided by GCM require client devices to register with GCM and obtain a registration token. To send a message to a specific device, the registration token is effectively the "device ID". So yes, you need to implement something similar to the RegistrationIntentService and InstanceIDListenerService described in the documentation.
The description in the documentation about needing to send the registration token to the App Server is misleading. That is only required for targeted messaging. The documentation for receiving topic messages states: "Note that, for topic messaging it's not required to send the registration token to your app server; however, if you do send it, your server can verify the validity of the token and get more information about the app that created it."