我尝试以 10 秒的周期间隔运行 JobScheduler。例如builder.setPeriodic(10000)。但无法在按钮单击时启动 TestJobService IntentService 并且不显示任何错误消息。
有谁能够帮助我。
public void onClick(View v){
ComponentName mServiceComponent = new ComponentName(this, TestJobService.class);
JobInfo.Builder builder = new JobInfo.Builder(kJobId++, mServiceComponent);
//Pass Parameter to Job Scheduler
PersistableBundle bundle = new PersistableBundle();
bundle.putString(DataDownloadService.EXTRA_PARAM_URL, DataDownloadService.URL);
builder.setExtras(bundle)
.setPersisted(true);
builder.setPeriodic(10000);//10 Seconds
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED);
builder.setRequiresDeviceIdle(true);
builder.setRequiresCharging(false); is charging or not
JobScheduler jobScheduler = (JobScheduler)getApplication().getSystemService(Context.JOB_SCHEDULER_SERVICE);
jobScheduler.schedule(builder.build());
}