当前位置: 首页>>代码示例>>Java>>正文


Java JobScheduler.cancelAll方法代码示例

本文整理汇总了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));
    }
}
 
开发者ID:Trumeet,项目名称:MiPushFramework,代码行数:19,代码来源:PushController.java

示例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);
}
 
开发者ID:isuperqiang,项目名称:AndroidKeepLivePractice,代码行数:38,代码来源:DaemonService.java

示例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;
}
 
开发者ID:frank240889,项目名称:AutoMusicTagFixer,代码行数:41,代码来源:GnService.java

示例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();
        }
    }
}
 
开发者ID:danielgimenes,项目名称:NasaPic,代码行数:14,代码来源:PeriodicWallpaperChangeService.java

示例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();
}
 
开发者ID:nejtv,项目名称:androidtv-sample,代码行数:6,代码来源:SyncUtils.java

示例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();
}
 
开发者ID:Vovchyk,项目名称:android-rss-feed-reader,代码行数:7,代码来源:WidgetUtils.java

示例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();
}
 
开发者ID:lifechurch,项目名称:nuclei-android,代码行数:6,代码来源:TaskScheduler.java

示例8: stopSync

import android.app.job.JobScheduler; //导入方法依赖的package包/类
private void stopSync() {
    JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
    if (jobScheduler != null) {
        jobScheduler.cancelAll();
    }
}
 
开发者ID:qiscus,项目名称:qiscus-sdk-android,代码行数:7,代码来源:QiscusSyncJobService.java

示例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();
}
 
开发者ID:googlesamples,项目名称:androidtv-sample-inputs,代码行数:10,代码来源:EpgSyncJobService.java

示例10: cancelAllJobs

import android.app.job.JobScheduler; //导入方法依赖的package包/类
public void cancelAllJobs(View v) {
	JobScheduler tm = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
	tm.cancelAll();
}
 
开发者ID:vogellacompany,项目名称:codeexamples-android,代码行数:5,代码来源:MainActivity.java


注:本文中的android.app.job.JobScheduler.cancelAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。