【发布时间】:2017-05-24 07:43:09
【问题描述】:
实际上我需要在应用程序图标中显示徽章,但我不知道如何获取徽章以及为什么当应用程序处于后台或应用程序未运行时 onMessageReceived 不调用。
public class Custom_FirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "FirebaseMsgService";
String activityName;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (remoteMessage == null)
return;
if (remoteMessage.getNotification() != null) {
Log.i(TAG, "Notification Body: " + remoteMessage.getNotification().getBody());
}
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.i(TAG, "Data Payload: " + remoteMessage.getData().toString());
try{
//boolean from_bg = Boolean.parseBoolean(remoteMessage.getData().get("from_bg").toString());
Map<String, String> data = remoteMessage.getData();
boolean show_fg = Boolean.parseBoolean(data.get("show_fg"));
.....
【问题讨论】:
-
如果你想在后台接收消息,你必须使用有效载荷数据,如firebase.google.com/docs/cloud-messaging/android/receive中所述
-
你能说出你使用的是哪个设备吗?
-
一直被调用 onMessageReceived (应用程序前台或后台),您只需要接收“数据”有效负载(而不是“数据”和“通知”有效负载)。如果您同时发送“数据”和“通知”有效负载,当应用程序在前台时,将调用“onMessageReceived”。
-
我在前台发送“数据”和“通知”有效负载和 onMessageReceived,但不在后台,您对在应用图标中显示徽章有任何想法吗?
标签: android firebase firebase-cloud-messaging badge