本文整理匯總了Java中android.app.job.JobScheduler.cancel方法的典型用法代碼示例。如果您正苦於以下問題:Java JobScheduler.cancel方法的具體用法?Java JobScheduler.cancel怎麽用?Java JobScheduler.cancel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.app.job.JobScheduler
的用法示例。
在下文中一共展示了JobScheduler.cancel方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onSharedPreferenceChanged
import android.app.job.JobScheduler; //導入方法依賴的package包/類
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
final String remindersKey = getString(R.string.pref_key_reminders);
if (key.equals(remindersKey)) {
boolean enabled = sharedPreferences.getBoolean(remindersKey, false);
JobScheduler jobScheduler =
(JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
if (!enabled) {
jobScheduler.cancel(JOB_ID);
Log.d(TAG, "cancelling scheduled job");
} else {
long interval = AlarmManager.INTERVAL_HOUR;
JobInfo job = new JobInfo.Builder(JOB_ID,
new ComponentName(getPackageName(),
ScheduledJobService.class.getName()))
.setPersisted(true)
.setPeriodic(interval)
.build();
jobScheduler.schedule(job);
Log.d(TAG, "setting scheduled job for: " + interval);
}
}
}
示例2: startPolling
import android.app.job.JobScheduler; //導入方法依賴的package包/類
@TargetApi(21)
public static void startPolling(Context context) {
JobScheduler scheduler = (JobScheduler)
context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
final int JOB_ID = 1;
if (isBeenScheduled(JOB_ID, context)){
Log.i(TAG, "scheduler.cancel(JOB_ID)");
scheduler.cancel(JOB_ID);
} else{
Log.i(TAG, "scheduler.schedule(jobInfo)");
int pollInterval = QueryPreferences.getPollInterval(context);
Log.i(TAG, "the poll interval is: " + pollInterval + " ms");
JobInfo jobInfo = new JobInfo.Builder(
JOB_ID, new ComponentName(context, PollJobService.class))
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
.setPeriodic(pollInterval)
.setPersisted(true)
.build();
scheduler.schedule(jobInfo);
}
}
示例3: registerForNetworkAvailability
import android.app.job.JobScheduler; //導入方法依賴的package包/類
private static void registerForNetworkAvailability(Context context) {
JobScheduler jobScheduler = (JobScheduler) context.getSystemService(JOB_SCHEDULER_SERVICE);
if (jobScheduler == null) {
return;
}
int scheduleId = getScheduleId(context, ON_NETWORK_AVAILABLE_JOB_ID);
jobScheduler.cancel(scheduleId);
int r = jobScheduler.schedule(new JobInfo.Builder(scheduleId, new ComponentName(context, MobileMessagingJobService.class))
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.build());
if (r == JobScheduler.RESULT_SUCCESS) {
MobileMessagingLogger.d(TAG, "Registered job for connectivity updates");
} else {
MobileMessagingLogger.e(TAG, "Failed to register job for connectivity updates");
}
}
示例4: onResume
import android.app.job.JobScheduler; //導入方法依賴的package包/類
@Override
protected void onResume() {
super.onResume();
// Change locale to Klingon if Klingon UI option is set.
updateLocaleConfiguration();
// Schedule the KWOTD service if it hasn't already been started. It's necessary to do this here
// because the setting might have changed in Preferences.
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
if (sharedPrefs.getBoolean(Preferences.KEY_KWOTD_CHECKBOX_PREFERENCE, /* default */ true)) {
runKwotdServiceJob(/* isOneOffJob */ false);
} else {
// If the preference is unchecked, cancel the persisted job.
JobScheduler scheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
scheduler.cancel(KWOTD_SERVICE_PERSISTED_JOB_ID);
}
}
示例5: schedule
import android.app.job.JobScheduler; //導入方法依賴的package包/類
@Override
public boolean schedule(Context context, TaskInfo taskInfo) {
ThreadUtils.assertOnUiThread();
if (!BackgroundTaskScheduler.hasParameterlessPublicConstructor(
taskInfo.getBackgroundTaskClass())) {
Log.e(TAG, "BackgroundTask " + taskInfo.getBackgroundTaskClass()
+ " has no parameterless public constructor.");
return false;
}
JobInfo jobInfo = createJobInfoFromTaskInfo(context, taskInfo);
JobScheduler jobScheduler =
(JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
if (taskInfo.shouldUpdateCurrent()) {
jobScheduler.cancel(taskInfo.getTaskId());
}
int result = jobScheduler.schedule(jobInfo);
return result == JobScheduler.RESULT_SUCCESS;
}
示例6: cancelJobAlarmSub
import android.app.job.JobScheduler; //導入方法依賴的package包/類
/**
* 用於在不需要服務運行的時候取消 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();
}
示例7: scheduleOrCancel
import android.app.job.JobScheduler; //導入方法依賴的package包/類
/**
* 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;
}
示例8: cancelJob
import android.app.job.JobScheduler; //導入方法依賴的package包/類
public static void cancelJob(Context context, int jobId)
{
JobScheduler jobScheduler = getJobScheduler(context);
jobScheduler.cancel(jobId);
// Construct a new JobInfo.Builder
//jobScheduler.schedule(builder.build());
}
示例9: stopAlarmForAlphys
import android.app.job.JobScheduler; //導入方法依賴的package包/類
/**
* Cancels any previous alarms set for Alphys.
* @param c App context.
*/
public static void stopAlarmForAlphys(Context c) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
JobScheduler scheduler = (JobScheduler) c.getSystemService(Context.JOB_SCHEDULER_SERVICE);
scheduler.cancel(TAG_JOB_ID);
} else {
Intent alphysIntent = new Intent(c, AlphysReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(c, 0, alphysIntent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);
am.cancel(pendingIntent);
}
}
示例10: stopWaitingForNetwork
import android.app.job.JobScheduler; //導入方法依賴的package包/類
private void stopWaitingForNetwork() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
JobScheduler js = (JobScheduler)getSystemService(Context.JOB_SCHEDULER_SERVICE);
js.cancel(ALARM_CONNECTIVITY_JOB);
} else {
AndroidUtil.setPackageComponentEnabled(this, NetworkReceiver.class, false);
}
}
示例11: hideWaitingForConnectionNotification
import android.app.job.JobScheduler; //導入方法依賴的package包/類
private void hideWaitingForConnectionNotification() {
mNotificationManager.cancel(R.id.wiki_waiting_notification);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Cancel the job, if need be.
JobScheduler js = (JobScheduler)getSystemService(Context.JOB_SCHEDULER_SERVICE);
js.cancel(WIKI_CONNECTIVITY_JOB);
} else {
// Shut off the listener, if need be.
AndroidUtil.setPackageComponentEnabled(this, WikiServiceConnectivityListener.class, false);
}
}
示例12: cancel
import android.app.job.JobScheduler; //導入方法依賴的package包/類
@Override
public void cancel(Context context, int taskId) {
ThreadUtils.assertOnUiThread();
JobScheduler jobScheduler =
(JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
jobScheduler.cancel(taskId);
}
示例13: bindJobScheduler
import android.app.job.JobScheduler; //導入方法依賴的package包/類
@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);
}
示例14: cancelArtworkDownloadRetries
import android.app.job.JobScheduler; //導入方法依賴的package包/類
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 {
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).apply();
}
}
示例15: cancelComplicationUpdateJob
import android.app.job.JobScheduler; //導入方法依賴的package包/類
static void cancelComplicationUpdateJob(Context context) {
JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
jobScheduler.cancel(ARTWORK_COMPLICATION_JOB_ID);
if (BuildConfig.DEBUG) {
Log.d(TAG, "Job cancelled");
}
// Disable the BOOT_COMPLETED receiver to reduce memory pressure on boot
ComponentName bootReceivedComponentName = new ComponentName(context,
ArtworkComplicationBootReceiver.class);
context.getPackageManager().setComponentEnabledSetting(bootReceivedComponentName,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}