JobInfo jobInfo =
new JobInfo.Builder(AUTO_UPDATE_JOB_ID, new ComponentName(context, AutoUpdateJobService.class))
.setRequiresCharging(true)// 充电电量在百分之九十以上满足该条件
.setRequiresBatteryNotLow(true)
.setRequiresDeviceIdle(true)//idle状态调用,一般手机息屏静止35分钟左右会触发idle
.setRequiresStorageNotLow(true)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
.setPeriodic(UPDATE_PERIODIC)//周期性调用,最少间隔十五分钟
.build();
Object scheduler = context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
if (scheduler instanceof JobScheduler) {
int result = ((JobScheduler) scheduler).schedule(jobInfo);
RunLog.i(LOG_TAG, "finish the scheduler of job service, result:" + result);
AiEngineSpManager.setLastSchedulePluginPkgAutoUpdateTime(context, System.currentTimeMillis());
}
/** * 加入重试提示任务 */ public void addRetryJobServiceToPromptUpdate() { ComponentName jobService = new ComponentName(ContextHolder.getAppContext(), UpdatePromptJobService.class); addJob(new JobInfo.Builder(JobIdConstants.UPGRADE_PROMPT_JOB_ID, jobService).setMinimumLatency(PROMPT_PERIODIC)//如果设置几秒,也会执行 .setRequiresBatteryNotLow(true) .setRequiresStorageNotLow(true) .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) .build()); RunLog.i(LOG_TAG, "addRetryJobServiceToPromptUpdate.."); }