2017-09-04 51 views

回答

0

我设法找到一种方法来知道用户是否禁用了“后台活动”。 不知道它是最好的解决方案,但看起来像它的工作:

在onDestroy我的粘性服务,我安排了一个工作(与JobScheduler)有时间限制。

作业运行时,我检查我的粘性服务是否仍然被销毁,而不是再次启动。 如果是这种情况,我尝试从工作中启动服务,并检查成功:

ComponentName componentName = startService(serviceIntent); 
if(componentName == null){ 
    // we could not start the service, so user probably disabled the background activity 
}