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

标签 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}]

Intent 中没有消息正文,只有消息 ID! 谢谢!

最佳答案

试试这个

  @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"));
        }

关于android - 点击FCM通知消息时如何获取消息正文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38867199/

相关文章:

java - 获取括号之间的字符串

Android通知打开后重新出现

ios - 如何在 AppDelegate 之外放置 FCM 的通知授权请求?

Firebase 消息 : Successful but not delivered

android - Android中进度条结束时如何更改 Activity ?

android - SQLite中如何替换表

java - FTP - Android 客户端和 Java 服务器

android - 每个通知都有自己的包含唯一数据的 PendingIntent

android - 警报管理器未触发

java - Android 应用程序在后台时如何从 firebase-message 获取数据