Skip to content

Instantly share code, notes, and snippets.

@terrelewis
Created May 30, 2019 14:02
Show Gist options
  • Save terrelewis/c8058c0ac3b1f81c8378e71642b41a99 to your computer and use it in GitHub Desktop.
Save terrelewis/c8058c0ac3b1f81c8378e71642b41a99 to your computer and use it in GitHub Desktop.
@Override
public void onReceive(Context context, Intent intent) {
Timber.d("In 15 min alarm check");
JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
boolean isMyJobScheduled();
List<JobInfo> jobs = scheduler.getAllPendingJobs();
for (JobInfo jobInfo : jobs) {
if (jobInfo.getId() == YOUR_JOB_ID)
isMyJobScheduled = true;
}
if(!isMyJobScheduled){
ComponentName serviceName = new ComponentName(context, AlarmStatusCheckJobService.class);
JobInfo jobInfo = new JobInfo.Builder(YOUR_JOB_ID, serviceName)
.setPeriodic(Constants.FIFTEEN_MINUTES) //once every 15 minutes
.setPersisted(true)
.build();
int result = scheduler.schedule(jobInfo);
}
AlarmScheduler.scheduleNextCheckAlarm(context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment