当应用在后台时,通知消息通过notification发送,当通知被点击,应用启动时,如何获取消息正文?
意图是:
Bundle[{google.sent_time=1470813025421, from=568540028909,
google.message_id=0:1470813025865549%31bd1c9631bd1c96,
collapse_key=com.google.firebase.quickstart.fcm}]
intent中没有消息正文,只有消息id!谢谢!
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"));
}
很抱歉,你想做的是不可能的。
目前无法访问
的(body, title, icon…)信息。通知打开时启动的活动的notification-message
您可以访问通知消息的data组件。
一个可能的替代方案是使用data-message
消息并创建您自己的自定义通知和自定义逻辑。
参见notification-message
vs data-message
:
https://firebase.google.com/docs/cloud-messaging/concept-options notifications_and_data_messages
PS:如果你能通过firebase支持页面报告一个特性请求,那将会很有用。
通过这种方式,团队可以正确地确定未来功能的优先级。https://firebase.google.com/support/contact/bugs-features/