Java Code Examples for android.app.job.JobScheduler#cancel()

The following examples show how to use android.app.job.JobScheduler#cancel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeepAliveJobService.java    From Tok-Android with GNU General Public License v3.0 7 votes vote down vote up
private void scheduleJob() {
    int timeDelay = 2000;
    int id = 100;
    JobInfo.Builder builder =
        new JobInfo.Builder(id, new ComponentName(getApplication(), KeepAliveJobService.class));
    if (Build.VERSION.SDK_INT >= 24) {
        builder.setMinimumLatency(timeDelay);
        builder.setOverrideDeadline(timeDelay);
        builder.setMinimumLatency(timeDelay);
        builder.setBackoffCriteria(timeDelay, JobInfo.BACKOFF_POLICY_LINEAR);
    } else {
        builder.setPeriodic(timeDelay);
    }
    builder.setPersisted(true);
    builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
    builder.setRequiresCharging(false);
    JobInfo info = builder.build();
    JobScheduler jobScheduler =
        (JobScheduler) this.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    jobScheduler.cancel(id);
    jobScheduler.schedule(info);
}
 
Example 2
Source File: BrightnessIdleJob.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public static void scheduleJob(Context context) {
    JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);

    JobInfo pending = jobScheduler.getPendingJob(JOB_ID);
    JobInfo jobInfo =
            new JobInfo.Builder(JOB_ID, new ComponentName(context, BrightnessIdleJob.class))
                    .setRequiresDeviceIdle(true)
                    .setRequiresCharging(true)
                    .setPeriodic(TimeUnit.HOURS.toMillis(24)).build();

    if (pending != null && !pending.equals(jobInfo)) {
        jobScheduler.cancel(JOB_ID);
        pending = null;
    }

    if (pending == null) {
        jobScheduler.schedule(jobInfo);
    }
}
 
Example 3
Source File: GcmJobService.java    From ti.goosh with MIT License 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.O)
static void scheduleJob(Context context, Bundle extras) {
	ComponentName jobComponentName = new ComponentName(context.getPackageName(), GcmJobService.class.getName());
	JobScheduler mJobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
	JobInfo existingInfo = mJobScheduler.getPendingJob(JOB_ID);
	if (existingInfo != null) {
		mJobScheduler.cancel(JOB_ID);
	}

	JobInfo.Builder jobBuilder = new JobInfo.Builder(JOB_ID, jobComponentName)
			.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY).setTransientExtras(extras);
	int result = mJobScheduler.schedule(jobBuilder.build());
	if (result != JobScheduler.RESULT_SUCCESS) {
		Log.e(LCAT, "Could not start job, error code: " + result);
	}
}
 
Example 4
Source File: MainActivity.java    From android-JobScheduler with Apache License 2.0 6 votes vote down vote up
/**
 * Executed when user clicks on FINISH LAST TASK.
 */
public void finishJob(View v) {
    JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
    List<JobInfo> allPendingJobs = jobScheduler.getAllPendingJobs();
    if (allPendingJobs.size() > 0) {
        // Finish the last one
        int jobId = allPendingJobs.get(0).getId();
        jobScheduler.cancel(jobId);
        Toast.makeText(
                MainActivity.this, String.format(getString(R.string.cancelled_job), jobId),
                Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(
                MainActivity.this, getString(R.string.no_jobs_to_cancel),
                Toast.LENGTH_SHORT).show();
    }
}
 
Example 5
Source File: MainActivity.java    From Easy_xkcd with Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Timber.d( "received result" +  resultCode + "from request" + requestCode);
    if (requestCode == 1) {
        switch (resultCode) {
            case RESULT_OK: //restart the activity when something major was changed in the settings
                updateTaskRunning = true; // Prevents creation of a new updateTask in onRestart()
                finish();
                startActivity(getIntent());
                break;
            case UPDATE_ALARM:
                JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
                if (prefHelper.getNotificationInterval() != 0) {
                    jobScheduler.cancel(UPDATE_JOB_ID);
                    jobScheduler.schedule(new JobInfo.Builder(UPDATE_JOB_ID, new ComponentName(this, ComicNotifierJob.class))
                            .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                            .setPeriodic(prefHelper.getNotificationInterval())
                            .setPersisted(true)
                            .build()
                    );
                    Timber.d("Job rescheduled!");
                } else {
                    jobScheduler.cancel(UPDATE_JOB_ID);
                    Timber.d("Job canceled!");
                }
                break;
        }
    } else if (requestCode == 2 && resultCode == FilePickerActivity.RESULT_OK) {
        ((FavoritesFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG)).importFavorites(data); //The import can only be started when FavoritesFragment is visible, so this cast should never fail
    } else if (requestCode == 3 && resultCode == Activity.RESULT_OK) {
        finish();
        startActivity(getIntent());
        //TODO select drawer item here, do this after merge
    }
}
 
Example 6
Source File: WatchDogService.java    From HelloDaemon with MIT License 5 votes vote down vote up
/**
 * 用于在不需要服务运行的时候取消 Job / Alarm / Subscription.
 *
 * 因 WatchDogService 运行在 :watch 子进程, 请勿在主进程中直接调用此方法.
 * 而是向 WakeUpReceiver 发送一个 Action 为 WakeUpReceiver.ACTION_CANCEL_JOB_ALARM_SUB 的广播.
 */
public static void cancelJobAlarmSub() {
    if (!DaemonEnv.sInitialized) return;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        JobScheduler scheduler = (JobScheduler) DaemonEnv.sApp.getSystemService(JOB_SCHEDULER_SERVICE);
        scheduler.cancel(HASH_CODE);
    } else {
        AlarmManager am = (AlarmManager) DaemonEnv.sApp.getSystemService(ALARM_SERVICE);
        if (sPendingIntent != null) am.cancel(sPendingIntent);
    }
    if (sDisposable != null) sDisposable.dispose();
}
 
Example 7
Source File: QiscusNetworkCheckerJobService.java    From qiscus-sdk-android with Apache License 2.0 5 votes vote down vote up
private void stopJob() {
    QiscusLogger.print(TAG, "stopJob");
    JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
    if (jobScheduler != null) {
        jobScheduler.cancel(STATIC_JOB_ID);
    }
}
 
Example 8
Source File: BGTask.java    From transistor-background-fetch with MIT License 5 votes vote down vote up
static void cancel(Context context, String taskId, int jobId) {
    Log.i(BackgroundFetch.TAG, "- cancel taskId=" + taskId + ", jobId=" + jobId);
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && (jobId != 0)) {
        JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
        if (jobScheduler != null) {
            jobScheduler.cancel(jobId);
        }
    } else {
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        if (alarmManager != null) {
            alarmManager.cancel(BGTask.getAlarmPI(context, taskId));
        }
    }
}
 
Example 9
Source File: FloatJobService.java    From RelaxFinger with GNU General Public License v2.0 5 votes vote down vote up
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());
}
 
Example 10
Source File: CBWatcherService.java    From Clip-Stack with MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void bindJobScheduler() {
    // JobScheduler for auto clean sqlite
    JobInfo job = new JobInfo.Builder(JOB_ID, new ComponentName(this, SyncJobService.class))
            .setRequiresCharging(true)
            .setRequiresDeviceIdle(true)
            .setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
            .setPeriodic(24*60*60*1000)
            .setPersisted(true)
            .build();
    JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
    jobScheduler.cancel(JOB_ID);
    jobScheduler.schedule(job);
}
 
Example 11
Source File: AppUtils.java    From ClassSchedule with Apache License 2.0 5 votes vote down vote up
/**
 * 取消widget更新任务
 */
public static void cancelUpdateWidgetService(Context context) {
    LogUtil.e(AppUtils.class, "cancelUpdateWidgetService");
    JobScheduler scheduler = (JobScheduler) context
            .getSystemService(Context.JOB_SCHEDULER_SERVICE);
    scheduler.cancel(UPDATE_WIDGET_JOB_ID);
}
 
Example 12
Source File: ScanJobScheduler.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
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();
    }

    mBackgroundScanJobFirstRun = true;
}
 
Example 13
Source File: BootCompleteReceiver.java    From InviZible with GNU General Public License v3.0 5 votes vote down vote up
private void stopRefreshTorUnlockIPs(Context context) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
        return;
    }
    JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    if (jobScheduler != null) {
        jobScheduler.cancel(mJobId);
    }
}
 
Example 14
Source File: TimeZoneUpdateIdler.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Unschedules the TimeZoneUpdateIdler job service.
 *
 * @param context Context to use to get a job scheduler.
 */
public static void unschedule(Context context) {
    JobScheduler jobScheduler =
            (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    Slog.d(TAG, "unschedule() called");
    jobScheduler.cancel(TIME_ZONE_UPDATE_IDLE_JOB_ID);
}
 
Example 15
Source File: AndroidJobScheduler.java    From android_job_scheduler with Apache License 2.0 4 votes vote down vote up
public static void cancelJob(Context context, Integer jobId) {
    JobScheduler scheduler = context.getSystemService(JobScheduler.class);
    scheduler.cancel(jobId);
}
 
Example 16
Source File: QiscusSyncJobService.java    From qiscus-sdk-android with Apache License 2.0 4 votes vote down vote up
private void stopSync() {
    JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
    if (jobScheduler != null) {
        jobScheduler.cancel(STATIC_JOB_ID);
    }
}
 
Example 17
Source File: RemoteVerifyJob.java    From Auditor with MIT License 4 votes vote down vote up
static void cancel(final Context context) {
    final JobScheduler scheduler = context.getSystemService(JobScheduler.class);
    scheduler.cancel(PERIODIC_JOB_ID);
    scheduler.cancel(FIRST_RUN_JOB_ID);
}
 
Example 18
Source File: PhotosContentJob.java    From proofmode with GNU General Public License v3.0 4 votes vote down vote up
public static void cancelJob(Context context) {
    JobScheduler js = context.getSystemService(JobScheduler.class);
    js.cancel(PHOTOS_CONTENT_JOB);
}
 
Example 19
Source File: BackgroundDownloadService.java    From shortyz with GNU General Public License v3.0 4 votes vote down vote up
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());
}
 
Example 20
Source File: BrightnessIdleJob.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public static void cancelJob(Context context) {
    JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
    jobScheduler.cancel(JOB_ID);
}