在Android系统中,当我的应用程序启动前台服务时,如果用户在设置中关闭了通知权限,该服务真的是前台服务吗?
恐怕没有通知,它实际上是一项后台服务,不能保证会完成。
我在服务的onStartCommand函数中进行了此类工作:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "myId")
.setSmallIcon(R.drawable.all_downloads_icon)
.setContentTitle("my title")
.setContentText("you have started a notificaiton")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
Notification notification = builder.build();
startForeground(110,notification);
答案 0 :(得分:0)
答案是肯定的。 我使用adb shell查看服务信息,它仍然是前台服务。并感谢您提出问题的编辑建议。
adb shell
activity services DownloadService(your service's class name)
isForeground = true前景色Id = 110 frontantNoti = Notification(channel = myId pri = 0 contentView = null 振动=空声音=空默认值= 0x0标志= 0x40颜色= 0x00000000 vis = PRIVATE) createTime = -2s764ms startingBgTimeout =- lastActivity = -1s772ms restartTime = -2s763ms createdFromFg = true startRequested = true delayStop = false stopIfKilled = false callStart = true lastStartId = 5