【发布时间】:2017-04-22 17:24:58
【问题描述】:
在combined way阅读有关云消息的firebase文档,我在android设备中获取数据消息时遇到了问题。
var payload = {
notification: {
title: "Test",
body: "Test body"
},
data: {
score: "850",
close: "635.67"
}
};
我希望在 android 设备中的“onMessageReceived”处获得数据字段,但我只收到一条通知消息。我试图点击消息,但在“onMessageReceived”中仍然没有任何消息。
我添加了一个意图过滤器来触发主要活动,在通知有效负载中添加“clickAction”(如 firebase 参考中所述)和“click_action”(如我在某些问题中所见),我也得到了相同的结果。
清单
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@mipmap/ic_launcher" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/blue" />
<service
android:name=".connection.TestFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name=".connection.TestFirebaseIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
Java 代码:
public class FirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "TestFirebase";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
LogNotification.d(TAG, "NOTIFICATION - From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
LogNotification.d(TAG, "NOTIFICATION - Message data payload: " + remoteMessage.getData().toString());
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
LogNotification.d(TAG, "NOTIFICATION - Message Notification Body: " + remoteMessage.getData().toString());
}
}
}
一些提示?
【问题讨论】:
-
请添加您的 Java 代码
-
好的,我也添加清单。完成。
标签: android firebase firebase-cloud-messaging