I\'m trying to use the android Job Scheduler API and all I\'m trying to do is have the Job Scheduler run every 5 seconds. However when I run it, the corresponding service is
I was having this problem and after review some blogs and the official documentation, I realised that JobScheduler is having difference behavior on Android N(24 and 25). JobScheduler works with a minimum periodic of 15 mins.
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static void setJobScheduler(Context context){
Log.v(TAG, "Job Scheduler is starting");
JobScheduler jobScheduler = (JobScheduler)context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
ComponentName serviceName = new ComponentName(context, JobService.class);
JobInfo jobInfo;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
jobInfo = new JobInfo.Builder(JOB_ID, serviceName)
.setPeriodic(900000)
.build();
}else{
jobInfo = new JobInfo.Builder(JOB_ID, serviceName)
.setPeriodic(Constants.TIME_INTERVAL)
.build();
}
jobScheduler.schedule(jobInfo);
}