List of usage examples for android.content Context JOB_SCHEDULER_SERVICE
String JOB_SCHEDULER_SERVICE
To view the source code for android.content Context JOB_SCHEDULER_SERVICE.
Click Source Link
From source file:com.example.android.sampletvinput.syncservice.SyncUtils.java
/** Send the job to JobScheduler. **/ private static void scheduleJob(Context context, JobInfo job) { JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); jobScheduler.schedule(job);//from w w w.j av a 2 s .c o m }
From source file:com.commonsware.android.jobsched.content.DemoJobService.java
static void schedule(Context ctxt) { ComponentName cn = new ComponentName(ctxt, DemoJobService.class); JobInfo.TriggerContentUri trigger = new JobInfo.TriggerContentUri(CONTENT_URI, JobInfo.TriggerContentUri.FLAG_NOTIFY_FOR_DESCENDANTS); JobInfo.Builder b = new JobInfo.Builder(ME_MYSELF_AND_I, cn).addTriggerContentUri(trigger); JobScheduler jobScheduler = (JobScheduler) ctxt.getSystemService(Context.JOB_SCHEDULER_SERVICE); jobScheduler.schedule(b.build());//from w w w . j a v a2 s. c om }
From source file:com.example.android.sampletvinput.syncservice.SyncUtils.java
public static void cancelAll(Context context) { JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); jobScheduler.cancelAll();// w w w .j ava2s . c o m }
From source file:nuclei.task.TaskScheduler.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private static void cancelL(Context context, nuclei.task.Task<?> task) { JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); jobScheduler.cancel(task.getTaskId()); }
From source file:com.google.android.car.kitchensink.job.JobSchedulerFragment.java
@Nullable @Override//w w w . java2 s. c o m public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View v = inflater.inflate(R.layout.job_scheduler, container, false); mScheduleButton = (Button) v.findViewById(R.id.schedule_button); mScheduleButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { scheduleJob(); } }); mRefreshButton = (Button) v.findViewById(R.id.refresh_button); mRefreshButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { refreshCurrentJobs(); } }); mNetworkGroup = (RadioGroup) v.findViewById(R.id.network_group); mDishNum = (EditText) v.findViewById(R.id.dish_num); mRequireCharging = (CheckBox) v.findViewById(R.id.require_charging); mRequireIdle = (CheckBox) v.findViewById(R.id.require_idle); mRequirePersisted = (CheckBox) v.findViewById(R.id.require_persisted); mJobScheduler = (JobScheduler) getContext().getSystemService(Context.JOB_SCHEDULER_SERVICE); mJobInfo = (TextView) v.findViewById(R.id.current_jobs); mCancelButton = (Button) v.findViewById(R.id.cancel_button); mCancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mJobScheduler.cancelAll(); refreshCurrentJobs(); } }); return v; }
From source file:nuclei.task.TaskScheduler.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private static void cancelAllL(Context context) { JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); jobScheduler.cancelAll();//w ww. j a v a 2 s . c o m }
From source file:com.google.android.apps.muzei.sync.TaskQueueService.java
private void cancelArtworkDownloadRetries() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); jobScheduler.cancel(LOAD_ARTWORK_JOB_ID); } else {/*w w w. j a v a 2 s . co m*/ AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.cancel(TaskQueueService.getArtworkDownloadRetryPendingIntent(this)); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); sp.edit().putInt(PREF_ARTWORK_DOWNLOAD_ATTEMPT, 0).commit(); } }
From source file:io.github.hidroh.materialistic.data.SyncDelegate.java
@UiThread public static void scheduleSync(Context context, Job job) { if (!Preferences.Offline.isEnabled(context)) { return;//from ww w . j a va 2s.c o m } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !TextUtils.isEmpty(job.id)) { JobInfo.Builder builder = new JobInfo.Builder(Long.valueOf(job.id).intValue(), new ComponentName(context.getPackageName(), ItemSyncJobService.class.getName())) .setRequiredNetworkType( Preferences.Offline.isWifiOnly(context) ? JobInfo.NETWORK_TYPE_UNMETERED : JobInfo.NETWORK_TYPE_ANY) .setExtras(job.toPersistableBundle()); if (Preferences.Offline.currentConnectionEnabled(context)) { builder.setOverrideDeadline(0); } ((JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(builder.build()); } else { Bundle extras = new Bundle(job.toBundle()); extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); Account syncAccount; AccountManager accountManager = AccountManager.get(context); Account[] accounts = accountManager.getAccountsByType(BuildConfig.APPLICATION_ID); if (accounts.length == 0) { syncAccount = new Account(SYNC_ACCOUNT_NAME, BuildConfig.APPLICATION_ID); accountManager.addAccountExplicitly(syncAccount, null, null); } else { syncAccount = accounts[0]; } ContentResolver.requestSync(syncAccount, MaterialisticProvider.PROVIDER_AUTHORITY, extras); } }
From source file:com.google.android.apps.muzei.sync.TaskQueueService.java
private void scheduleRetryArtworkDownload() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); jobScheduler.schedule(new JobInfo.Builder(LOAD_ARTWORK_JOB_ID, new ComponentName(this, DownloadArtworkJobService.class)) .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY).build()); } else {/*w ww . jav a 2 s.c o m*/ SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); int reloadAttempt = sp.getInt(PREF_ARTWORK_DOWNLOAD_ATTEMPT, 0); sp.edit().putInt(PREF_ARTWORK_DOWNLOAD_ATTEMPT, reloadAttempt + 1).commit(); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); long retryTimeMillis = SystemClock.elapsedRealtime() + (1 << reloadAttempt) * 2000; am.set(AlarmManager.ELAPSED_REALTIME, retryTimeMillis, TaskQueueService.getArtworkDownloadRetryPendingIntent(this)); } }
From source file:com.google.android.apps.muzei.sync.TaskQueueService.java
public static Intent maybeRetryDownloadDueToGainedConnectivity(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); List<JobInfo> pendingJobs = jobScheduler.getAllPendingJobs(); for (JobInfo pendingJob : pendingJobs) { if (pendingJob.getId() == LOAD_ARTWORK_JOB_ID) { return TaskQueueService.getDownloadCurrentArtworkIntent(context); }/* ww w.j av a 2 s . c om*/ } return null; } return (PreferenceManager.getDefaultSharedPreferences(context).getInt(PREF_ARTWORK_DOWNLOAD_ATTEMPT, 0) > 0) ? TaskQueueService.getDownloadCurrentArtworkIntent(context) : null; }