我在应用商店上有一个拥有50000用户的应用程序。最近,我更新了我的Android Studio并将SDK编译到27。我进行了一些更改以支持Android 8的更改,包括通知更改(例如,通知应具有唯一通道)。在运行Android 8的Android One手机上进行了测试,一切都很顺利。 在更新应用程序后,我在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个这样的错误。每一个都有相同的日志,大约有5000多次崩溃,涉及约10个用户。因此,显然应用程序正在循环崩溃。
我遇到的问题是,这些日志没有提供任何日志,可以让我看到我的应用程序中发起此崩溃的源。 有没有办法找出哪个类抛出了这个崩溃?有什么帮助吗?
此外,我有这个通知的代码:
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);