本文整理汇总了Java中android.app.job.JobScheduler.cancelAll方法的典型用法代码示例。如果您正苦于以下问题:Java JobScheduler.cancelAll方法的具体用法?Java JobScheduler.cancelAll怎么用?Java JobScheduler.cancelAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.job.JobScheduler
的用法示例。
在下文中一共展示了JobScheduler.cancelAll方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setServiceEnable
import android.app.job.JobScheduler; //导入方法依赖的package包/类
/**
* Set XMPush sdk enable
* @param enable enable
* @param context context param
*/
public static void setServiceEnable (boolean enable, Context context) {
if (enable && isAppMainProc(context)) {
MiPushClient.registerPush(wrapContext(context), APP_ID, APP_KEY);
} else {
MiPushClient.unregisterPush(wrapContext(context));
// Force stop and disable services.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
scheduler.cancelAll();
}
context.stopService(new Intent(context, XMPushService.class));
}
}
示例2: onStartCommand
import android.app.job.JobScheduler; //导入方法依赖的package包/类
@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);
}
示例3: onPostExecute
import android.app.job.JobScheduler; //导入方法依赖的package包/类
@Override
protected void onPostExecute(Boolean res){
Log.d("res",res+" " + (mConnectedFrom == API_INITIALIZED_AFTER_CONNECTED));
//Schedule initialization if was not possible this time
if(!res){
//when number of intents is 5
//inform the user that API could not be initialized and the cause
if(sCountIntents == 5){
Toast toast = Toast.makeText(sContext, sContext.getString(R.string.could_not_init_api) + mMsg, Toast.LENGTH_LONG);
View view = toast.getView();
TextView text = (TextView) view.findViewById(android.R.id.message);
text.setTextColor(ContextCompat.getColor(sContext, R.color.grey_900));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
text.setTextAppearance(R.style.CustomToast);
}
else {
text.setTextAppearance(sContext,R.style.CustomToast);
}
view.setBackground(ContextCompat.getDrawable(sContext, R.drawable.background_custom_toast) );
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
sCountIntents = 0;
//Stop trying to initialize API
JobScheduler jobScheduler = (JobScheduler) sContext.getApplicationContext().getSystemService(Context.JOB_SCHEDULER_SERVICE);
jobScheduler.cancelAll();
}
else {
Job.scheduleJob(sContext);
sCountIntents++;
}
}
//Notify to user
else {
Intent intent = new Intent();
intent.setAction(Constants.GnServiceActions.ACTION_API_INITIALIZED);
LocalBroadcastManager.getInstance(sContext).sendBroadcastSync(intent);
}
sAsyncApiInitialization = null;
}
示例4: unschedulePeriodicWallpaperChange
import android.app.job.JobScheduler; //导入方法依赖的package包/类
public static void unschedulePeriodicWallpaperChange(Context context) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
JobScheduler scheduler = (JobScheduler) context
.getSystemService(Context.JOB_SCHEDULER_SERVICE);
if (scheduler.getAllPendingJobs().size() > 0) {
scheduler.cancelAll();
String unscheduledMessage = context.getResources()
.getString(R.string.periodic_change_unscheduled);
Toast.makeText(context, unscheduledMessage, Toast.LENGTH_SHORT).show();
}
}
}
示例5: cancelAll
import android.app.job.JobScheduler; //导入方法依赖的package包/类
public static void cancelAll(Context context) {
JobScheduler jobScheduler =
(JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
jobScheduler.cancelAll();
}
示例6: cancelUpdateNewsPeriodicallyByJobScheduler
import android.app.job.JobScheduler; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void cancelUpdateNewsPeriodicallyByJobScheduler(@NonNull Context context) {
JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
jobScheduler.cancel(UPDATE_NEWS_PERIODICALLY_JOB_ID);
jobScheduler.cancelAll();
}
示例7: cancelAllL
import android.app.job.JobScheduler; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void cancelAllL(Context context) {
JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
jobScheduler.cancelAll();
}
示例8: stopSync
import android.app.job.JobScheduler; //导入方法依赖的package包/类
private void stopSync() {
JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
if (jobScheduler != null) {
jobScheduler.cancelAll();
}
}
示例9: cancelAllSyncRequests
import android.app.job.JobScheduler; //导入方法依赖的package包/类
/**
* 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();
}
示例10: cancelAllJobs
import android.app.job.JobScheduler; //导入方法依赖的package包/类
public void cancelAllJobs(View v) {
JobScheduler tm = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
tm.cancelAll();
}