【问题标题】:FCM Notifications not getting called in background for Oreo奥利奥没有在后台调用 FCM 通知
【发布时间】:2018-08-14 17:23:22
【问题描述】:

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

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

如果我的应用从最近删除中清除,我使用数据消息作为通知消息将不会出现

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

对于 Oreo,我仅在应用未连接到 xmpp 且未连接到前台时才会收到通知。我的 onMessageReceived 方法被调用了。

但是,当应用被杀死或从最近的应用中删除时,则不会发生同样的情况。

编辑:我在一加 3 设备上试过。

感谢任何帮助。

【问题讨论】:

  • 它是什么类型的设备?某些手机​​具有后台终止功能,该功能会禁用在后台接收消息的能力。
  • 试过一加3
  • 你是用high priority发送消息吗?
  • 你成功了吗?
  • 三星设备上没有收到通知。您是否设法使这项工作适用于所有设备?

标签: android firebase firebase-cloud-messaging android-8.0-oreo


【解决方案1】:

现在回答可能为时已晚,但 One Plus 手机有一项称为电池优化的功能。关闭应用的电池优化后,您将开始接收后台通知。我的一加 5T 也有同样的问题。

【讨论】:

  • @Siddhant 非常感谢 .. 你有没有找到任何程序化的解决方法?除了手动禁用的东西:/
  • @Victor 我不认为这个问题可以通过编程方式解决,因为它是 OEM 特定的问题。 :(
【解决方案2】:

Oreo 引入了通知渠道的概念。检查here

在启动时创建一个频道:

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相同

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多