Firebase 云消息传递因升级到 Oreo 而停止
Firebase cloud messaging stopped with upgrade to Oreo
我刚刚开始 Android 开发,并在 运行 向导之后设法让 Firebase 消息传递正常工作。我能够在 Nexus 5X 运行 Nougat 上收到后台通知。但是后来我的 5X 升级到 Oreo 并且 Firebase 通知从那以后就没有用了。我听说过后台执行限制,但因为我才刚刚开始,所以我不知道我实际上需要做什么才能让它再次运行。有没有关于这个的文章?我从头开始尝试一个新项目,希望向导已更新,但没有任何变化。我正在使用应用程序广播消息和主题订阅消息,没有使用设备令牌。
请使用最新版本的 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
当您定位 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);
}
更改您的 Builder 构造函数
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(applicationContext, **ID you have put in the Notification Channel**)
最后您可以从生成器创建通知
notificationManager.notify("0", notificationBuilder.build())
参考:https://developer.android.com/guide/topics/ui/notifiers/notifications.html#ManageChannels
我刚刚开始 Android 开发,并在 运行 向导之后设法让 Firebase 消息传递正常工作。我能够在 Nexus 5X 运行 Nougat 上收到后台通知。但是后来我的 5X 升级到 Oreo 并且 Firebase 通知从那以后就没有用了。我听说过后台执行限制,但因为我才刚刚开始,所以我不知道我实际上需要做什么才能让它再次运行。有没有关于这个的文章?我从头开始尝试一个新项目,希望向导已更新,但没有任何变化。我正在使用应用程序广播消息和主题订阅消息,没有使用设备令牌。
请使用最新版本的 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
当您定位 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);
}
更改您的 Builder 构造函数
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(applicationContext, **ID you have put in the Notification Channel**)
最后您可以从生成器创建通知
notificationManager.notify("0", notificationBuilder.build())
参考:https://developer.android.com/guide/topics/ui/notifiers/notifications.html#ManageChannels