3

There is a php code to prepare a bundle for sending notification to firebae :

$registrationIds = array( $_GET['id'] );
// prep the bundle
$msg = array
(
    'body'  => $_GET['body'],
    'title'     => $_GET['title'],
    'vibrate'   => 1,
    'sound'     => 1,
);
$fields = array
(
    'registration_ids'  => $registrationIds,
    'notification'          => $msg
);

$headers = array
(
    'Authorization: key=' . API_ACCESS_KEY,
    'Content-Type: application/json'
);

I want same in java, i did all well and getting response 200 from firebase. but i dont know how to get registration-id . As done in php like :

$registrationIds = array( $_GET['id'] );

Please help me to find out the registration-id.

avy
  • 417
  • 1
  • 9
  • 21
  • 1
    on java : `request.getQueryString()` // you will get a=1&b=2 ...etc then split – Riad Aug 28 '16 at 07:59
  • Are you looking to [get a query parameter in Java](http://stackoverflow.com/search?q=get+query+parameter+in+java)? – Frank van Puffelen Aug 28 '16 at 15:29
  • I am trying to access [notification service] (https://firebase.google.com/docs/cloud-messaging/send-message) of firebase as : HTTP POST request https://fcm.googleapis.com/fcm/send Content-Type:application/json Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA { "data": { "score": "5x1", "time": "15:10" }, "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..." } but i dont how to get "to" parameter for client – avy Aug 29 '16 at 04:56

1 Answers1

1

To get the registrationId of a device(iOS or Android) the device needs to send/store it in a DB some where. I recommend using the realtime database provided by firebase.

  • First to get registrationId from the iOS App. Use let token = FIRInstanceID.instanceID().token(). This Token is known as the registrationId
  • Take this token and store it in your DB.
  • Server side you need to get that token out of your DB and place it as the value for the registration_ids or as the value for the "to" key. That should be it.

What about the "to"

So it's well laid out on how to use "to" in this StackoverflowPost

You don't get the "to" parameter from the client.

Community
  • 1
  • 1
edesilets
  • 180
  • 2
  • 8