我无法使用setPersisted(true)
成功安排JobSchedulerService。我的AndroidManifest.xml中有RECEIVE_BOOT_COMPLETED
权限。我得到的错误是:
system_process W/JobSchedulerService: Not scheduling this Job(job:<job_id>/<package_name>.MyJobService) before NTP established:1467230016977
有谁知道造成这种情况的原因是什么?如果我再次运行我的应用程序而只是注释掉setPersisted(true)
,那么一切正常。相关代码:
final JobInfo job = new JobInfo.Builder(MyJobService.JOB_ID, new ComponentName(context, MyJobService.class))
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.setPeriodic(PERIOD_MILLI)
.setPersisted(true) // If I remove this line, it works fine
.build();
JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
int returnVal = jobScheduler.schedule(job);
我的AndroidManifest.xml:
<service
android:name="<package_name>.MyJobService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="true"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>