2017-10-09 119 views
3

我剛剛開始使用Android開發,並在運行嚮導後設法讓Firebase消息傳遞工作。我能夠在運行Nougat的Nexus 5X上收到背景通知。但隨後我的5X升級到奧利奧,並且Firebase通知從此不起作用。我聽說過後臺執行的限制,但由於我剛剛開始,我不知道我必須做些什麼才能讓它再次運行。有沒有關於此的寫作?我從頭開始嘗試一個新項目,希望向導已經更新,但沒有變化。我正在使用應用程序廣播消息和主題訂閱消息,沒有使用設備令牌。Firebase雲消息停止升級到Oreo

+0

您是否閱讀過:https://developer.android.com/about/versions/oreo/background.html以及您發送郵件的優先級:https://firebase.google.com/docs/cloud-messaging/概念選項#設置優先級信息 –

+0

我讀過,但很難弄清楚我實際上可能需要做什麼。另外一個遷移點是使用FCM選擇性地喚醒應用程序以接收消息,我認爲這正是我一開始做的事情,所以我不明白爲什麼它不起作用。 –

回答

3

請使用最新版本的FCM sdk。

FCM sdk在4月份推出了對Android O的支持,如果您使用的是舊版本,您的應用將無法在Android O中收到消息並可能崩潰。

請參閱最新版本在這裏:https://firebase.google.com/support/release-notes/android

PS:火力SDK已被移到谷歌Maven倉庫。
一定要看看這裏的最新指示: https://firebase.google.com/docs/android/setup#manually_add_firebase

+0

我的Firebase依賴線是: compile'c​​om.google.firebase:firebase-messaging:10.0.1 SDK經理說我完全是最新版本,Android Studio說我在最新版本。如果有更新版本的任何東西,我不知道我該如何找出它。 –

+0

當前版本爲11.4.2,每兩週發佈次要版本 –

+0

因此,Firebase助手嚮導尚未更新以獲取新版本? –

3

當你定位到Android 8.0(API等級26),你必須實現一個或多個通知信道顯示通知給用戶。如果您不瞄準Android 8.0(API級別26),但您的應用在運行Android 8.0(API級別26)的設備上使用,則您的應用的行爲與在運行Android 7.1(API級別25)或更低級別的設備上的行爲相同。

如果你改變你的目標版本爲安卓8.0(API等級26),你必須做到以下幾點變化

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    String id = "id_product";//This will be enter when creating Builder 
    // The user-visible name of the channel. 
    CharSequence name = "Product"; 
    // The user-visible description of the channel. 
    String description = "Notifications regarding our products"; 
    int importance = NotificationManager.IMPORTANCE_MAX; 
    NotificationChannel mChannel = new NotificationChannel(id, name, importance); 
    // Configure the notification channel. 
    mChannel.setDescription(description); 
    mChannel.enableLights(true); 
    // Sets the notification light color for notifications posted to this 
    // channel, if the device supports this feature. 
    mChannel.setLightColor(Color.RED); 
    notificationManager.createNotificationChannel(mChannel); 
    } 

更改您的生成器構造

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(applicationContext, **ID you have put in the Notification Channel**) 

最後,你可以創建通知來自Builder

notificationManager.notify("0", notificationBuilder.build()) 

參考文獻:https://developer.android.com/guide/topics/ui/notifiers/notifications.html#ManageChannels