2017-09-04 35 views

回答

0

我設法找到一種方法來知道用戶是否禁用了「後臺活動」。 不知道它是最好的解決方案,但看起來像它的工作:

在onDestroy我的粘性服務,我安排了一個工作(與JobScheduler)有時間限制。

作業運行時,我檢查我的粘性服務是否仍然被銷燬,而不是再次啓動。 如果是這種情況,我嘗試從工作中啓動服務,並檢查成功:

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