@Override public boolean cancel() { logd("Canceling job: " + jobId); jobScheduler.cancel(jobId); return true; }
public void cancelSchedule(Context context) { JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); jobScheduler.cancel(ScanJob.getImmediateScanJobId(context)); jobScheduler.cancel(ScanJob.getPeriodicScanJobId(context)); if (mBeaconNotificationProcessor != null) { mBeaconNotificationProcessor.unregister(); } }
@Override public void cancel(int jobId) throws RemoteException { int vuid = VBinder.getCallingUid(); synchronized (mJobStore) { boolean changed = false; Iterator<Map.Entry<JobId, JobConfig>> iterator = mJobStore.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<JobId, JobConfig> entry = iterator.next(); JobId job = entry.getKey(); JobConfig config = entry.getValue(); if (job.vuid == vuid && job.clientJobId == jobId) { changed = true; mScheduler.cancel(config.virtualJobId); iterator.remove(); break; } } if (changed) { saveJobs(); } } }
@Override public void cancelAll() throws RemoteException { int vuid = VBinder.getCallingUid(); synchronized (mJobStore) { boolean changed = false; Iterator<Map.Entry<JobId, JobConfig>> iterator = mJobStore.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<JobId, JobConfig> entry = iterator.next(); JobId job = entry.getKey(); if (job.vuid == vuid) { JobConfig config = entry.getValue(); mScheduler.cancel(config.virtualJobId); changed = true; iterator.remove(); break; } } if (changed) { saveJobs(); } } }
@Override public void cancel(int jobId) { try { getJobScheduler().cancel(jobId); } catch (Exception e) { // https://gist.github.com/vRallev/5d48a4a8e8d05067834e mCat.e(e); } TransientBundleCompat.cancel(mContext, jobId, null); }
private void cancelScheduledUpdate(int appWidgetId) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getJobScheduler().cancel(appWidgetId); } else { mAlarmManager.cancel(createRefreshPendingIntent(appWidgetId)); } }
@Test public void cancelSingleJob() { jobScheduler.schedule( new JobInfo.Builder(99, new ComponentName(context, "component_class_name")) .setPeriodic(1000) .build()); assertThat(jobScheduler.getAllPendingJobs()).isNotEmpty(); jobScheduler.cancel(99); assertThat(jobScheduler.getAllPendingJobs()).isEmpty(); }
@Test public void cancelNonExistentJob() { jobScheduler.schedule( new JobInfo.Builder(99, new ComponentName(context, "component_class_name")) .setPeriodic(1000) .build()); assertThat(jobScheduler.getAllPendingJobs()).isNotEmpty(); jobScheduler.cancel(33); assertThat(jobScheduler.getAllPendingJobs()).isNotEmpty(); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1) private void manageJobScheduler(boolean start) { JobScheduler jobs= (JobScheduler)getSystemService(JOB_SCHEDULER_SERVICE); if (start) { JobInfo.Builder b=new JobInfo.Builder(JOB_ID, new ComponentName(this, DemoJobService.class)); PersistableBundle pb=new PersistableBundle(); if (download.isChecked()) { pb.putBoolean(KEY_DOWNLOAD, true); b.setExtras(pb).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY); } else { b.setRequiredNetworkType(JobInfo.NETWORK_TYPE_NONE); } b.setPeriodic(getPeriod()).setPersisted(false) .setRequiresCharging(false).setRequiresDeviceIdle(true); jobs.schedule(b.build()); } else { jobs.cancel(JOB_ID); } }
private void manageJobScheduler(boolean start) { if (start) { JobInfo.Builder b=new JobInfo.Builder(JOB_ID, new ComponentName(this, DemoJobService.class)); PersistableBundle pb=new PersistableBundle(); if (download.isChecked()) { pb.putBoolean(KEY_DOWNLOAD, true); b.setExtras(pb).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY); } else { b.setRequiredNetworkType(JobInfo.NETWORK_TYPE_NONE); } b.setPeriodic(getPeriod()).setPersisted(false) .setRequiresCharging(false).setRequiresDeviceIdle(true); jobs.schedule(b.build()); } else { jobs.cancel(JOB_ID); } }
jobScheduler.cancel(ScanJob.getImmediateScanJobId(context));
/** * Schedules or cancels the job, depending on the configuration * * @return true if the job could be scheduled. */ public static boolean scheduleOrCancel(Context context, Configuration configuration) { JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); if (!configuration.hosts.automaticRefresh) { Log.d(TAG, "scheduleOrCancel: Cancelling Job"); scheduler.cancel(JOB_ID); return true; } Log.d(TAG, "scheduleOrCancel: Scheduling Job"); ComponentName serviceName = new ComponentName(context, RuleDatabaseUpdateJobService.class); JobInfo jobInfo = new JobInfo.Builder(JOB_ID, serviceName) .setRequiresCharging(true) .setRequiresDeviceIdle(true) .setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED) .setPersisted(true) .setPeriodic(TimeUnit.DAYS.toMillis(1)) .build(); int result = scheduler.schedule(jobInfo); if (result == JobScheduler.RESULT_SUCCESS) Log.d(TAG, "Job scheduled"); else Log.d(TAG, "Job not scheduled"); return result == JobScheduler.RESULT_SUCCESS; }
static void cancelTodayForecastJob(Context context) { JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); if (scheduler != null) { scheduler.cancel(JOB_ID_TODAY_FORECAST); } }
private static void cancelJob(Context context) { JobScheduler jss; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { jss = context.getSystemService(JobScheduler.class); } else { jss = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); } Log.v(TAG, "Canceling job"); jss.cancel(JOB_ID); } }
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private void stopUsingJobService() { JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); assert scheduler != null; scheduler.cancel(JOB_ID); }
private void cancelJob() { JobScheduler scheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); if (scheduler != null) { scheduler.cancel(JOB_ID); } Toast.makeText(this, "Job Service canceled", Toast.LENGTH_SHORT).show(); }
private static void cancelJob(Context context) { LOGGER.info("Unscheduling background downloads"); JobScheduler scheduler = (JobScheduler)context.getSystemService(Context.JOB_SCHEDULER_SERVICE); scheduler.cancel(JobSchedulerId.BACKGROUND_DOWNLOAD.id()); }
public static void scheduleService(Context context) { JobScheduler js = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); JobInfo.Builder builder = new JobInfo.Builder(JOB_ID, new ComponentName(context.getPackageName(), FloatJobService.class.getName())); builder.setPersisted(true); builder.setPeriodic(3 * 1000); js.cancel(JOB_ID); js.schedule(builder.build()); } }