当应用程序在后台时,通知消息通过通知传递,当点击通知时,应用程序启动,我如何获取消息正文?
目的是这样的:
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/