通过升级到Oreo,Firebase云消息已停止

Ste*_*ior 6 android firebase-cloud-messaging android-8.0-oreo

我刚刚开始使用Android开发,并设法在运行向导后使Firebase消息传递正常工作.我能够在运行Nougat的Nexus 5X上收到背景通知.但随后我的5X升级到Oreo并且Firebase通知从那时起就没有用.我听说过后台执行限制,但由于我刚刚开始,我不知道为了让它再次运行我实际上必须做些什么.这有什么写作吗?我从头开始尝试了一个新项目,希望向导已经更新,但没有变化.我正在使用应用程序广播消息和主题订阅消息,没有使用设备令牌.

小智 8

当您定位到Android 8.0(API级别26)时,您必须实施一个或多个通知渠道以向用户显示通知.如果您没有定位Android 8.0(API级别26),但您的应用程序用于运行Android 8.0(API级别26)的设备上,则您的应用程序的行为与运行Android 7.1(API级别25)或更低版本的设备上的行为相同.

如果您将目标版本更改为Android 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);
  }
Run Code Online (Sandbox Code Playgroud)

更改您的Builder构造函数

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(applicationContext, **ID you have put in the Notification Channel**)
Run Code Online (Sandbox Code Playgroud)

最后,您可以从Builder创建通知

notificationManager.notify("0", notificationBuilder.build())
Run Code Online (Sandbox Code Playgroud)

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


Die*_*ini 4

请使用最新版本的 FCM sdk。

FCM sdk 在 4 月份引入了对 Android O 的支持,如果您使用旧版本,您的应用程序将无法在 Android O 中接收消息,并且可能会崩溃。

请在此处查看最新版本:https ://firebase.google.com/support/release-notes/android

PS:firebase SDK 已移至 Google Maven 存储库。
请务必在此处查看最新说明: https://firebase.google.com/docs/android/setup#manually_add_firebase