因此,我在商店中有一个拥有 50000 名用户的应用程序。最近我更新了我的 android studio 并将 SDK 编译为 27。我做了一些更改以支持 android 8 更改,包括通知更改(例如通知应该具有唯一 channel )。在 Android One 手机(运行 android 8)上对此进行了测试。一切都很顺利。 在 Playstore 上更新应用程序后,我在 Android 8 设备(主要是 Google Pixel 手机)上看到这些崩溃
Fatal Exception: android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=-2 contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 color=0xffffcf00 actions=3 vis=PRIVATE)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1768)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
我在 Crashlytics 上看到了其中的 7 个错误。每个都有相同的日志,大约 10 个用户有大约 5000 次崩溃。所以,显然应用程序在循环中崩溃。
我遇到的问题是这些日志不提供任何日志,从那里我可以看到我的应用程序中引发此崩溃的来源。 有什么办法可以找出是哪个类(class)引发了这次崩溃?有帮助吗?
我还有这个通知代码:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = notificationManager.getNotificationChannel(id);
if (mChannel == null) {
mChannel = new NotificationChannel(id, name, importance);
mChannel.setDescription(description);
notificationManager.createNotificationChannel(mChannel);
}
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(context,id);
builder.setContentTitle(pushMessages.size() + context.getString(R.string.new_notification))
.setContentIntent(pendingIntent)
.setContentText(pushMessages.get(0))
.setStyle(inboxStyle)
.setGroup(GROUP_KEY_NOTIFICATIONS)
.setGroupSummary(true)
.setAutoCancel(true);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setSmallIcon(R.drawable.notification_img)
.setColor(context.getResources().getColor(R.color.settings_yellow));
} else {
builder.setSmallIcon(R.mipmap.ic_launcher);
}
summaryNotification = builder.build();
notificationManager.notify(i, summaryNotification);
最佳答案
您忘记为通知设置 channel ID。
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) builder.setChannelId(youChannelID);
if
语句是可选的,取决于您的 Min SDK 级别。
关于android - 前台启动通知错误,服务通知 channel 无效 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51587863/