Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get "registration_ids" from Firebase FCM?

From FCM documentation here tells me how to send message to a device group, so I've to send something as followed:

https://android.googleapis.com/gcm/notification
Content-Type:application/json
Authorization:key=API_KEY
project_id:SENDER_ID

{
   "operation": "create",
   "notification_key_name": "appUser-Chris",
   "registration_ids": ["4", "8", "15", "16", "23", "42"]
}


However, I don't found there is any clear explanation told me how to get "registration_ids" from Firebase FCM.
I could only get "registration token" using FirebaseInstanceId.getInstance().getToken().
So anyone can tell me how to get "registration_ids" please?

like image 218
elliotching Avatar asked Mar 21 '17 14:03

elliotching


People also ask

What is Registration_ids in FCM?

The registration_ids parameter refers to the Registration Tokens you want to add in that specific Device Group. Described as: An ID generated by the FCM SDK for each client app instance. Required for single device and device group messaging. Note that registration tokens must be kept secret.

What is registration_IDs in Firebase?

"registration_ids"is an array of the registration tokens acquired by calling FirebaseInstanceId.getInstance().getToken()on a device. If you put multiple registration tokens in the array, the same push notification will be sent to each.

How do I get the installation ID of a firebase device?

To retrieve a Firebase installation ID: Firebase services can authenticate Firebase installations with auth tokens retrieved from FIS. For example, when designing A/B tests for Remote Config, you can authenticate a targeted test device using an installation auth token.

Why am I still receiving FCM notifications from Firebase?

Until Firebase notifies the client app, some of the app's services might still target the ID—for example, a Firebase installation might continue to receive FCM notifications for a few hours.

How do I Register my Firebase project?

To register, open the Firebase console. You'll be asked to enter your project name and accept all terms. Once you've successfully created your project, you will see the project overview page on which you can select which platform your application is.


1 Answers

"registration_ids" is an array of the registration tokens acquired by calling FirebaseInstanceId.getInstance().getToken() on a device. If you put multiple registration tokens in the array, the same push notification will be sent to each.

If you only want to send a notification to one device with a registration_id of 4, your "registration_ids" array need only contain one value like so: "registration_ids": ["4"]

If you want to send a notification to multiple devices, call FirebaseInstanceId.getInstance().getToken() on each device to get the token then populate the array with values like you already have.

like image 84
kira_codes Avatar answered Sep 30 '22 12:09

kira_codes