点击FCM通知消息时如何获取消息正文?

刘世都*_*刘世都 5 android android-notifications firebase-cloud-messaging firebase-notifications

当应用程序处于后台时,通知消息通过通知发送,当通知点击时,应用程序启动,我如何获取消息正文?

意图是这样的:

    Bundle[{google.sent_time=1470813025421, from=568540028909, 
google.message_id=0:1470813025865549%31bd1c9631bd1c96,
 collapse_key=com.google.firebase.quickstart.fcm}]
Run Code Online (Sandbox Code Playgroud)

意图没有消息体,只有消息ID!谢谢!

Jag*_*ngh 4

尝试这个

  @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"));
        }
Run Code Online (Sandbox Code Playgroud)