我正在开发接收 FCM(火基消息云)的 android 应用程序,当应用程序在后台或关闭时 android 系统接收通知并正确显示它,但是当应用程序进入前台时不显示通知,我检查了扩展 FirebaseMessagingService 的服务,它没有运行,我不知道如何让它运行。
服务代码:
public class MyService extends FirebaseMessagingService {
public MyService() {
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
}
}
list 代码:
<service android:name=".MyService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
主要 Activity 代码:
startService(new Intent(this,MyService.class));
最佳答案
Firebase 云消息 提供不同的消息类型以供使用。这些是:
FirebaseMessagingService
处理任何数据通知.如果您处理数据消息,您仍然可以手动显示通知 现在更具体地说
消息的类型取决于消息对象内部的内容。你应该关心
notification
和 data
里面的字段。如果您指定
notification
对象(它是您的推送通知的标题和正文)并且不包括 data
object - 那么你的消息类型是通知如果反之亦然,请仅指定
data
对象,则类型为数据结合这两种类型会导致最后一种类型
因此,如果您只想使用推送通知显示一些信息,请考虑使用通知类型。
您可以在 official documentation page 上找到更多信息
关于android - FirebaseMessagingService 未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58216282/