gpt4 book ai didi

android - 当应用程序在后台时,onMessageReceived 方法不会触发

转载 作者:行者123 更新时间:2023-11-29 16:57:56 26 4
gpt4 key购买 nike

实际上我需要在应用程序图标中显示徽章,但我不知道如何获取徽章以及为什么当应用程序处于后台或应用程序未运行时 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"));
.....

最佳答案

有两种类型的 FCM

notification 消息:仅当您的应用处于前台时,使用此消息类型发送负载才会触发 onMessageReceived()

data 消息:发送带有此特定消息类型的负载会触发 onMessageReceived(),无论您的应用程序是在前台还是后台。

引用:https://firebase.google.com/docs/cloud-messaging/android/receive#handling_messages

关于android - 当应用程序在后台时,onMessageReceived 方法不会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44152037/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com