Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send notification to specific users with FCM?

I prepared the receiver for FCM and can send a notification to all devices.

gcm-http.googleapis.com/gcm/send with this link can send to target users who is registered and post to the target devices like below json :

 {      "notification": {                 "title": "sample Title",                 "text": "sample text"   },            "to" : "[registration id]"          } 

However, I need to send notifications to target users which I choose, via email or name...etc . For example:

{      "notification": {                 "title": "sample Title",                 "text": "sample text"   },            "to" : "[email or name or sex ...]"          } 

How can I do that? Do I need to create a web server or something else?

like image 613
Olcay Sönmez Avatar asked Jun 08 '16 11:06

Olcay Sönmez


1 Answers

Did I need to create a web server

Yes. You need a place where you can map name/email to registration IDs. These registration IDs must be included in the request to FCM, for example

{     'registration_ids': ['qrgqry34562456', '245346236ef'],     'notification': {         'body': '',         'title': ''     },     'data': {      } } 

will send the push to 'qrgqry34562456' and '245346236ef'.

The registration ID you use in the call is the one that's called 'token' in this callback in the app.

public class MyService extends FirebaseInstanceIdService {     @Override     public void onTokenRefresh() {     } } 
like image 85
Tim Avatar answered Sep 19 '22 20:09

Tim