閱讀有關雲消息的firebase文檔combined way,我在Android設備中獲取數據消息時遇到了問題。如何在後臺獲取Firebase組合消息app
var payload = {
notification: {
title: "Test",
body: "Test body"
},
data: {
score: "850",
close: "635.67"
}
};
我期望在Android設備的'onMessageReceived'中獲取數據字段,但我只收到通知消息。我嘗試點擊該消息,但仍然沒有收到'onMessageReceived'。
我已經添加了一個intent過濾器來觸發主要活動,在通知有效載荷中添加'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代碼,請 –
好的,我也添加了清單。完成。 –