繁体   English   中英

FCM通知未在Oreo的后台调用

[英]FCM Notifications not getting called in background for Oreo

当用户未连接到xmpp时,我正在使用FCM通知进行聊天。

FCM中有两种通知模式。1.通知消息2.数据消息

如果将我的应用程序从最近的状态清除,我将使用数据消息作为通知消息

这种方法适用于除Oreo以外的所有版本。

对于Oreo,如果应用程序未连接到xmpp且处于前台,我只会收到通知。 我的onMessageReceived方法被调用。

但是,仅对于Oreo,当该应用程序被杀或从最新消息中删除时,情况不会发生。

编辑:我在One Plus 3设备上尝试过。

任何帮助表示赞赏。

答案可能为时已晚,但One Plus手机具有一项称为电池优化的功能。 关闭应用程序的电池优化功能后,您将立即开始接收后台通知。 我的One Plus 5T遇到了同样的问题。

从奥利奥(Oreo)引入了通知渠道的概念。 在这里检查。

在启动时创建频道:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    // Create the NotificationChannel
    CharSequence name = getString(R.string.channel_name);
    String description = getString(R.string.channel_description);
    int importance = NotificationManager.IMPORTANCE_DEFAULT;
    NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
    mChannel.setDescription(description);
    // Register the channel with the system; you can't change the importance
    // or other notification behaviors after this
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            NOTIFICATION_SERVICE);
    notificationManager.createNotificationChannel(mChannel);
}

在清单中设置ID:

<meta-data
        android:name="com.google.firebase.messaging.default_notification_channel_id"
        android:value="@string/notification_channel_id"/>

notification_channel_id与变量CHANNEL_ID相同

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM