0

在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);
4

1 回答 1

0

答案是肯定的。我用adb shell看服务信息,还是前台服务。并感谢您的问题编辑建议。

adb shell
activity services DownloadService(your service's class name)

isForeground=true foregroundId=110 foregroundNoti=Notification(channel=myId pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 color=0x00000000 vis=PRIVATE) createTime=-2s764ms startingBgTimeout=--lastActivity=-1s772ms restartTime=-2s763ms createdFromFg=true startRequested=true delayStop=false stopIfKilled=false callStart=true lastStartId=5

于 2019-06-12T01:52:59.200 回答