android - 启动前台的错误通知,服务通知的无效通道:
问题描述
所以,我在商店里有一个拥有 50000 个用户的应用程序。最近我更新了我的 android studio 并将 SDK 编译到 27。我做了一些更改以支持 android 8 更改,包括通知更改(例如通知应该有唯一的通道)。在 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 多次崩溃。因此,显然应用程序在循环中崩溃了。
我遇到的问题是这些日志没有提供任何日志,我可以从中看到导致此崩溃的应用程序中的源。 有什么办法可以找出哪个班级引发了这次崩溃?有什么帮助吗?
我也有这个通知代码:
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);
解决方案
您忘记为通知设置频道 ID。
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) builder.setChannelId(youChannelID);
该if
语句是可选的,取决于您的 Min SDK 级别。
推荐阅读
- mongodb - MeteorJS queries are super slow if users have active sessions
- python - 安装beautifulsoup4和bs4
- r - Rstudio Connections 选项卡无法帮助我在代码中引用对象名称
- sockets - TCP的Welcome端口vs连接端口以及三次握手的目的
- latex - 我可以将 Pandoc 排版引擎更改为 XeTeX 或 LuaTex 吗?
- python - 为什么当我使用“break”函数时,我的“if”语句没有退出?
- python - python中邻居节点的总权重
- fonts - 如何在 UFO 3 中使用组合字符?
- protege - 封闭世界推理师门生
- foreign-keys - Informix - 创建表时创建外键