gpt4 book ai didi

android - 未收到 FIrebase 消息内容

转载 作者:行者123 更新时间:2023-11-29 01:09:40 27 4
gpt4 key购买 nike

我正在收到通知,但无法从通知中获取通知正文。我创建了一个 firebase 服务类并添加了依赖项(编译 'com.google.firebase:firebase-messaging:10.2.6')并编辑了 list (

<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>)

可能是什么原因?

import android.util.Log;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "FCM Service";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO: 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.
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
}
}

我没有收到任何日志。

最佳答案

**FCM消息有两种类型**

Display Messages: These messages trigger the onMessageReceived() callback only when your app is in foreground

Data Messages: Theses messages trigger the onMessageReceived() callback even if your app is in foreground/background/killed

不要忘记此服务添加 list 文件

<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>

<service
android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>

在 list 文件中添加 Internet Permision

<uses-permission android:name="android.permission.INTERNET" />

关于android - 未收到 FIrebase 消息内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44106690/

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