我遇到了 Playstore 报告的大量异常。来自 Android P 的 RemoteServiceException。
我正在创建 android 前台服务,然后调用 startForegound(with channel)。
但 99.9% 只有 9.0(android P) 用户报告 RemoteServiceException。我检查了我是否为该服务制作了通知渠道。我还检查了我是否在 OREO 之后为 os 调用了 startForegroundService。
每个代码都没有问题。
但是我发现我多次调用 startForegroundService() ,但是在第一次创建 Service 时只调用了一次 onCreate() 。所以 onCreate() 中的 startForeground() 只被调用一次。
但是,如果我将 startForeground() 放在 onStartCommand() 中,那么它的调用次数也将与我调用 startForegroundService() 的次数一样多。因为每当您调用 startService/startForegroundService 时它也会被调用(即使已经创建了 Service 的实例)。
你认为这是异常的原因吗?
而 mboy 对/sf/answers/3587621901/的评论 也说了类似的话。
android foreground-service remoteserviceexception android-9.0-pie
startForeground() 需要创建 NotificationChannel 以便它会在 Oreo 设备的启动器图标上显示徽章编号 1
如何以编程方式隐藏/禁用它?
因为 Galaxy S8(Oreo) 显示徽章编号 1。而 Android 8.0 模拟器也显示点。
这就是我现在所做的。但是 setShowBadge(false) 不起作用
编辑1:
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationChannel tmpC = new NotificationChannel(id, "basic", NotificationManager.IMPORTANCE_MIN);
tmpC.setShowBadge(false);
manager.createNotificationChannel(tmpC);
Notification notification = new NotificationCompat.Builder(this, id)
.setChannelId(id)
.setAutoCancel(true)
.build();
startForeground(getPackageName().hashCode(), notification);
Run Code Online (Sandbox Code Playgroud) 我们使用私有应用程序商店,因此我们可以上传低于26目标sdk的应用程序。如何构建目标版本低于 26(oreo) 的 apk?
Android studio 3.3 显示构建发布错误。它说我应该使用目标 sdk 26 或更高版本。