Java Code Examples for android.app.job.JobScheduler#cancelAll()
The following examples show how to use
android.app.job.JobScheduler#cancelAll() .
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: YourLocalWeather.java From your-local-weather with GNU General Public License v3.0 | 8 votes |
@Override public void onCreate() { super.onCreate(); appendLog(this, TAG,"Default locale:", Resources.getSystem().getConfiguration().locale.getLanguage()); PreferenceManager.getDefaultSharedPreferences(this) .edit() .putString(Constants.PREF_OS_LANGUAGE, Resources.getSystem().getConfiguration().locale.getLanguage()) .apply(); LanguageUtil.setLanguage(this, PreferenceUtil.getLanguage(this)); sTheme = PreferenceUtil.getTheme(this); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.M) { JobScheduler jobScheduler = getSystemService(JobScheduler.class); appendLog(this, TAG, "scheduleStart at YourLocalWeather"); AppPreference.setLastSensorServicesCheckTimeInMs(this, 0); jobScheduler.cancelAll(); ComponentName serviceComponent = new ComponentName(this, StartAutoLocationJob.class); JobInfo.Builder builder = new JobInfo.Builder(StartAutoLocationJob.JOB_ID, serviceComponent); builder.setMinimumLatency(1 * 1000); // wait at least builder.setOverrideDeadline(3 * 1000); // maximum delay jobScheduler.schedule(builder.build()); } }
Example 2
Source File: MainActivity.java From your-local-weather with GNU General Public License v3.0 | 5 votes |
private void startAlarms() { appendLog(this, TAG, "scheduleStart at boot, SDK=", Build.VERSION.SDK_INT); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.M) { JobScheduler jobScheduler = getSystemService(JobScheduler.class); boolean scheduled = false; for (JobInfo jobInfo: jobScheduler.getAllPendingJobs()) { if (jobInfo.getId() > 0) { appendLog(this, TAG, "scheduleStart does not start - it's scheduled already"); scheduled = true; break; } } if (!scheduled) { appendLog(this, TAG, "scheduleStart at MainActivity"); AppPreference.setLastSensorServicesCheckTimeInMs(this, 0); jobScheduler.cancelAll(); ComponentName serviceComponent = new ComponentName(this, StartAutoLocationJob.class); JobInfo.Builder builder = new JobInfo.Builder(StartAutoLocationJob.JOB_ID, serviceComponent); builder.setMinimumLatency(1 * 1000); // wait at least builder.setOverrideDeadline(3 * 1000); // maximum delay jobScheduler.schedule(builder.build()); } } else { Intent intentToStartUpdate = new Intent("org.thosp.yourlocalweather.action.START_ALARM_SERVICE"); intentToStartUpdate.setPackage("org.thosp.yourlocalweather"); startService(intentToStartUpdate); } }
Example 3
Source File: DaemonService.java From AndroidKeepLivePractice with Apache License 2.0 | 5 votes |
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(TAG, "onStartCommand(): intent = [" + intent.toUri(0) + "], flags = [" + flags + "], startId = [" + startId + "]"); try { // 定时检查 WorkService 是否在运行,如果不在运行就把它拉起来 // Android 5.0+ 使用 JobScheduler,效果比 AlarmManager 好 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Log.i(TAG, "开启 JobService 定时"); JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); jobScheduler.cancelAll(); JobInfo.Builder builder = new JobInfo.Builder(1024, new ComponentName(getPackageName(), ScheduleService.class.getName())); builder.setPeriodic(WAKE_INTERVAL); builder.setPersisted(true); builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY); int schedule = jobScheduler.schedule(builder.build()); if (schedule <= 0) { Log.w(TAG, "schedule error!"); } } else { // Android 4.4- 使用 AlarmManager Log.i(TAG, "开启 AlarmManager 定时"); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); Intent alarmIntent = new Intent(getApplication(), DaemonService.class); PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 1024, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); am.cancel(pendingIntent); am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + WAKE_INTERVAL, WAKE_INTERVAL, pendingIntent); } } catch (Exception e) { Log.e(TAG, "e:", e); } // 简单守护开机广播 getPackageManager().setComponentEnabledSetting( new ComponentName(getPackageName(), DaemonService.class.getName()), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); return super.onStartCommand(intent, flags, startId); }
Example 4
Source File: DaemonService.java From AndroidKeepLivePractice with Apache License 2.0 | 5 votes |
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(TAG, "onStartCommand(): intent = [" + intent.toUri(0) + "], flags = [" + flags + "], startId = [" + startId + "]"); try { // 定时检查 WorkService 是否在运行,如果不在运行就把它拉起来 // Android 5.0+ 使用 JobScheduler,效果比 AlarmManager 好 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Log.i(TAG, "开启 JobService 定时"); JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); jobScheduler.cancelAll(); JobInfo.Builder builder = new JobInfo.Builder(1024, new ComponentName(getPackageName(), ScheduleService.class.getName())); builder.setPeriodic(WAKE_INTERVAL); builder.setPersisted(true); builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY); int schedule = jobScheduler.schedule(builder.build()); if (schedule <= 0) { Log.w(TAG, "schedule error!"); } } else { // Android 4.4- 使用 AlarmManager Log.i(TAG, "开启 AlarmManager 定时"); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); Intent alarmIntent = new Intent(getApplication(), DaemonService.class); PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 1024, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); am.cancel(pendingIntent); am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + WAKE_INTERVAL, WAKE_INTERVAL, pendingIntent); } } catch (Exception e) { Log.e(TAG, "e:", e); } // 简单守护开机广播 getPackageManager().setComponentEnabledSetting( new ComponentName(getPackageName(), DaemonService.class.getName()), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); return super.onStartCommand(intent, flags, startId); }
Example 5
Source File: QiscusCore.java From qiscus-sdk-android with Apache License 2.0 | 5 votes |
/** * Clear all current user qiscus data, you can call this method when user logout for example. */ public static void clearUser() { if (BuildVersionUtil.isOreoOrHigher()) { JobScheduler jobScheduler = (JobScheduler) appInstance.getSystemService(Context.JOB_SCHEDULER_SERVICE); if (jobScheduler != null) { jobScheduler.cancelAll(); } } localDataManager.clearData(); dataStore.clear(); QiscusCacheManager.getInstance().clearData(); EventBus.getDefault().post(QiscusUserEvent.LOGOUT); }
Example 6
Source File: AndroidJobScheduler.java From android_job_scheduler with Apache License 2.0 | 4 votes |
public static void cancelAllJobs(Context context) { JobScheduler scheduler = context.getSystemService(JobScheduler.class); scheduler.cancelAll(); }
Example 7
Source File: EpgSyncJobService.java From xipl with Apache License 2.0 | 4 votes |
/** * Cancels all pending jobs. * * @param context Application's context. */ public static void cancelAllSyncRequests(Context context) { JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); jobScheduler.cancelAll(); }
Example 8
Source File: MainActivity.java From android-JobScheduler with Apache License 2.0 | 4 votes |
/** * Executed when user clicks on CANCEL ALL. */ public void cancelAllJobs(View v) { JobScheduler tm = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); tm.cancelAll(); Toast.makeText(MainActivity.this, R.string.all_jobs_cancelled, Toast.LENGTH_SHORT).show(); }
Example 9
Source File: EpgSyncJobService.java From androidtv-sample-inputs with Apache License 2.0 | 4 votes |
/** * Cancels all pending jobs. * * @param context Application's context. */ public static void cancelAllSyncRequests(Context context) { JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); jobScheduler.cancelAll(); }
Example 10
Source File: myJobService.java From service with Apache License 2.0 | 4 votes |
public static void cancelJob(Context context) { JobScheduler jobScheduler = (JobScheduler) context.getSystemService(JobScheduler.class); jobScheduler.cancelAll(); }
Example 11
Source File: MainActivity.java From codeexamples-android with Eclipse Public License 1.0 | 4 votes |
public void cancelAllJobs(View v) { JobScheduler tm = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); tm.cancelAll(); }