Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how get message body when FCM notification message is tap?

When app is in background, the notification message is deliver by Notification, when the notification is tap, app is launch, how can i get the message body?

the intent is this:

    Bundle[{google.sent_time=1470813025421, from=568540028909, 
google.message_id=0:1470813025865549%31bd1c9631bd1c96,
 collapse_key=com.google.firebase.quickstart.fcm}]

no message body in intent, only message id! Thanks!

like image 533
刘世都 Avatar asked Aug 10 '16 07:08

刘世都


1 Answers

try this

  @Override
        public void onMessageReceived(RemoteMessage remoteMessage) {
            // TODO(developer): Handle FCM messages here.
            // If the application is in the foreground handle both data and notification messages here.
            // Also if you intend on generating your own notifications as a result of a received FCM
            // message, here is where that should be initiated. See sendNotification method below.
            Log.d(TAG, "From: " + remoteMessage.getFrom());
            Log.d(TAG, "From: " + remoteMessage.getData().get("message"));
    //        Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
// if you sending data with custom key
 Log.d(TAG, "Notification Message of custom key: " +remoteMessage.getData().get("your key"));
            sendNotification(remoteMessage.getData().get("message"));
        }
like image 171
Jagjit Singh Avatar answered Sep 19 '22 09:09

Jagjit Singh