簡體   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