Iqbal Iqbal - 3 years ago 97
Android Question

How to send String from php firebase notification to notification service in android?

I want to send a notification with the string of "room" from php. this is my code :

define( 'API_ACCESS_KEY', '--------------------------' );
#prep the bundle
$msg = array
'body' => $_GET['isi'],
'title' => $nama." mengirim pesan",
'icon' => 'myicon',/*Default Icon*/
'sound' => 'mySound',/*Default sound*/
'room' => $room //This is String I want to send
$fields = array
'to' => $registrationIds,
'notification' => $msg

$headers = array
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, '' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );

And I would like to receive a string of "room" here :

public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMessagingService";

public void onMessageReceived(RemoteMessage remoteMessage) {
sendNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());

How can i get String of "room" ?

Answer Source

notification message payloads only have specific parameters available for use (see here).

You're going to have to use a data message payload to add your custom key-value pair and then handle the messages accordingly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download