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


Java JobScheduler.schedule方法代码示例

本文整理汇总了Java中android.app.job.JobScheduler.schedule方法的典型用法代码示例。如果您正苦于以下问题:Java JobScheduler.schedule方法的具体用法?Java JobScheduler.schedule怎么用?Java JobScheduler.schedule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.job.JobScheduler的用法示例。


在下文中一共展示了JobScheduler.schedule方法的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);
        }
    }
}
 
开发者ID:talCrafts,项目名称:Udhari,代码行数:25,代码来源:SettingsActivity.java

示例2: onReceive

import android.app.job.JobScheduler; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    JobScheduler jobScheduler =
            (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    // If there are not pending jobs. Create a sync job and schedule it.
    List<JobInfo> pendingJobs = jobScheduler.getAllPendingJobs();
    if (pendingJobs.isEmpty()) {
        String inputId = context.getSharedPreferences(SyncJobService.PREFERENCE_EPG_SYNC,
                Context.MODE_PRIVATE).getString(SyncJobService.BUNDLE_KEY_INPUT_ID, null);
        if (inputId != null) {
            // Set up periodic sync only when input has set up.
            SyncUtils.setUpPeriodicSync(context, inputId);
        }
        return;
    }
    // On L/L-MR1, reschedule the pending jobs.
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
        for (JobInfo job : pendingJobs) {
            if (job.isPersisted()) {
                jobScheduler.schedule(job);
            }
        }
    }
}
 
开发者ID:nejtv,项目名称:androidtv-sample,代码行数:25,代码来源:RichBootReceiver.java

示例3: scheduleAddWatchNextRequest

import android.app.job.JobScheduler; //导入方法依赖的package包/类
public static void scheduleAddWatchNextRequest(Context context, ClipData clipData) {
    JobScheduler scheduler = (JobScheduler) context.getSystemService(JOB_SCHEDULER_SERVICE);

    PersistableBundle bundle = new PersistableBundle();
    bundle.putString(ID_KEY, clipData.getClipId());
    bundle.putString(CONTENT_ID_KEY, clipData.getContentId());
    bundle.putLong(DURATION_KEY, clipData.getDuration());
    bundle.putLong(PROGRESS_KEY, clipData.getProgress());
    bundle.putString(TITLE_KEY, clipData.getTitle());
    bundle.putString(DESCRIPTION_KEY, clipData.getDescription());
    bundle.putString(CARD_IMAGE_URL_KEY, clipData.getCardImageUrl());

    scheduler.schedule(new JobInfo.Builder(1,
            new ComponentName(context, AddWatchNextService.class))
            .setMinimumLatency(0)
            .setExtras(bundle)
            .build());
}
 
开发者ID:googlesamples,项目名称:leanback-homescreen-channels,代码行数:19,代码来源:AddWatchNextService.java

示例4: schedule

import android.app.job.JobScheduler; //导入方法依赖的package包/类
@SuppressWarnings("ConstantConditions")
public static void schedule(final Context context) {
    final JobScheduler scheduler = context.getSystemService(JobScheduler.class);

    for (final JobInfo job : scheduler.getAllPendingJobs()) {
        if (job.getId() == JOB_ID_PERIODIC) {
            return;
        }
    }

    final long interval = MINUTE *
            Integer.valueOf(DefaultSharedPrefUtils.getBackgroundServiceInterval(context));

    final ComponentName name = new ComponentName(context, PeriodicJob.class);

    final int result = scheduler.schedule(new JobInfo.Builder(JOB_ID_PERIODIC, name)
            .setPeriodic(interval)
            .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
            .build());

    if (result != JobScheduler.RESULT_SUCCESS) {
        Log.e(TAG, "Failed to schedule periodic job");
    }
}
 
开发者ID:Applications-Development,项目名称:SimpleRssReader,代码行数:25,代码来源:PeriodicJob.java

示例5: onCreate

import android.app.job.JobScheduler; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Create JobScheduler
    JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);

    //Create a component passing the JobService that we want to use
    ComponentName jobService =  new ComponentName(getPackageName(), MyJobService.class.getName());

    //Create a JobInfo passing a unique JOB_ID and the jobService
    //also set the periodic time to repeat this job
    JobInfo jobInfo =  new JobInfo.Builder(JOB_ID, jobService)
            .setPeriodic(REFRESH_INTERVAL)
            .build();

    jobScheduler.schedule(jobInfo);

}
 
开发者ID:micromasterandroid,项目名称:androidbeginners-Lesson3,代码行数:21,代码来源:MainActivity.java

示例6: 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);
    }
}
 
开发者ID:shier2nd,项目名称:LatestDiscounts,代码行数:23,代码来源:PollJobService.java

示例7: onReceive

import android.app.job.JobScheduler; //导入方法依赖的package包/类
@Override
    public void onReceive(Context context, Intent intent) {
        Log.d(getClass().getName(), "onReceive");

//        // Automatically open application
//        Intent bootIntent = new Intent(context, MainActivity.class);
//        bootIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//        context.startActivity(bootIntent);

        // Initiate background job for synchronizing with server content
        ComponentName componentName = new ComponentName(context, ContentSynchronizationJobService.class);
        JobInfo.Builder builder = new JobInfo.Builder(LiteracyApplication.CONTENT_SYNCRHONIZATION_JOB_ID, componentName);
        builder.setPeriodic(1000 * 60 * 30); // Every 30 minutes
        JobInfo jobInfo = builder.build();
        JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
        jobScheduler.schedule(jobInfo);

        /*if (StartPrefsHelper.scheduleAfterBoot(context)){
            scheduleAuthenticationJobs(context);
        } else {
            Log.i(getClass().getName(), "Authentication jobs won't be scheduled because the 7 days after first start-up haven't passed yet.");
        }*/

        scheduleAuthenticationJobs(context);
    }
 
开发者ID:elimu-ai,项目名称:authentication,代码行数:26,代码来源:BootReceiver.java

示例8: schedulePeriodic

import android.app.job.JobScheduler; //导入方法依赖的package包/类
private static void schedulePeriodic(Context context) {
    Timber.d("Scheduling a periodic task");

    JobInfo.Builder builder = new JobInfo.Builder(
            PERIODIC_ID, new ComponentName(context, QuoteJobService.class));


    builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
            .setPeriodic(PERIOD)
            .setBackoffCriteria(INITIAL_BACKOFF, JobInfo.BACKOFF_POLICY_EXPONENTIAL);


    JobScheduler scheduler = (JobScheduler) context.getSystemService(
            Context.JOB_SCHEDULER_SERVICE);

    int result = scheduler.schedule(builder.build());
    if (result == JobScheduler.RESULT_SUCCESS) {
        Timber.i("Job scheduled successfully!");
    } else {
        Timber.e("Job did not scheduled!");
    }

}
 
开发者ID:jkozh,项目名称:stockhawk,代码行数:24,代码来源:QuoteSyncJob.java

示例9: syncJob

import android.app.job.JobScheduler; //导入方法依赖的package包/类
private void syncJob() {
    QiscusAccount qiscusAccount = Qiscus.getQiscusAccount();

    Random rand = new Random();
    int randomValue = rand.nextInt(50);

    JobInfo jobInfo = new JobInfo.Builder(qiscusAccount.getId() + randomValue, componentName)
            .setPeriodic(TimeUnit.MINUTES.toMillis(15))
            .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
            .build();

    JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
    if (jobScheduler != null) {
        jobScheduler.schedule(jobInfo);
    }

}
 
开发者ID:qiscus,项目名称:qiscus-sdk-android,代码行数:18,代码来源:QiscusSyncJobService.java

示例10: waitForNetwork

import android.app.job.JobScheduler; //导入方法依赖的package包/类
private void waitForNetwork() {
    // SDK check!  We'll go with JobScheduler if we can.
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // JobScheduler time!  It's fancier!
        JobScheduler js = (JobScheduler)getSystemService(Context.JOB_SCHEDULER_SERVICE);
        JobInfo job = new JobInfo.Builder(
                ALARM_CONNECTIVITY_JOB,
                new ComponentName(this, AlarmServiceJobService.class))
                .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                .build();
        js.schedule(job);
    } else {
        // Otherwise, just use the ol' package component.
        AndroidUtil.setPackageComponentEnabled(this, NetworkReceiver.class, true);
    }
}
 
开发者ID:CaptainSpam,项目名称:geohashdroid,代码行数:17,代码来源:AlarmService.java

示例11: showWaitingForConnectionNotification

import android.app.job.JobScheduler; //导入方法依赖的package包/类
private void showWaitingForConnectionNotification() {
    Notification.Builder builder = getFreshNotificationBuilder()
            .setOngoing(true)
            .setContentTitle(getString(R.string.wiki_notification_waiting_for_connection_title))
            .setContentText(getString(R.string.wiki_notification_waiting_for_connection_content))
            .setSmallIcon(R.drawable.ic_stat_navigation_more_horiz)
            .setContentIntent(getBasicCommandIntent(QueueService.COMMAND_RESUME));

    mNotificationManager.notify(R.id.wiki_waiting_notification, builder.build());

    // If we have JobScheduler (SDK 21 or higher), use that.  Otherwise, go
    // with the old ConnectivityListener style.
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        JobScheduler js = (JobScheduler)getSystemService(Context.JOB_SCHEDULER_SERVICE);
        JobInfo job = new JobInfo.Builder(
                WIKI_CONNECTIVITY_JOB,
                new ComponentName(this, WikiServiceJobService.class))
                .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                .build();
        js.schedule(job);
    } else {
        // Make sure the connectivity listener's waiting for a connection.
        AndroidUtil.setPackageComponentEnabled(this, WikiServiceConnectivityListener.class, true);
    }
}
 
开发者ID:CaptainSpam,项目名称:geohashdroid,代码行数:26,代码来源:WikiService.java

示例12: scheduleJob

import android.app.job.JobScheduler; //导入方法依赖的package包/类
private static void scheduleJob(Context context) {
    JobScheduler scheduler =
            (JobScheduler)context.getSystemService(Context.JOB_SCHEDULER_SERVICE);

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);

    JobInfo info = getJobInfo(
            preferences.getBoolean("backgroundDownloadRequireUnmetered", true),
            preferences.getBoolean("backgroundDownloadAllowRoaming", false),
            preferences.getBoolean("backgroundDownloadRequireCharging", false));


    LOGGER.info("Scheduling background download job: " + info);

    int result = scheduler.schedule(info);

    if (result == JobScheduler.RESULT_SUCCESS) {
        LOGGER.info("Successfully scheduled background downloads");
    } else {
        LOGGER.log(Level.WARNING, "Unable to schedule background downloads");
    }
}
 
开发者ID:kebernet,项目名称:shortyz,代码行数:23,代码来源:BackgroundDownloadService.java

示例13: 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;
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:23,代码来源:BackgroundTaskSchedulerJobService.java

示例14: setupIfNeededPeriodicWallpaperChange

import android.app.job.JobScheduler; //导入方法依赖的package包/类
public static void setupIfNeededPeriodicWallpaperChange(Context context) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        Resources res = context.getResources();
        JobScheduler scheduler = (JobScheduler) context
                .getSystemService(Context.JOB_SCHEDULER_SERVICE);

        if (scheduler.getAllPendingJobs().size() == 0) {
            ComponentName serviceEndpoint = new ComponentName(context,
                    PeriodicWallpaperChangeService.class);
            JobInfo wallpaperChangeJob = new JobInfo.Builder(
                    PeriodicWallpaperChangeService.JOB_ID, serviceEndpoint)
                    .setRequiresCharging(false)
                    .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                    .setPersisted(true)
                    .setRequiresDeviceIdle(true)
                    .setPeriodic(PERIOD_IN_HOURS * 60 * 60 * 1000)
                    .build();

            scheduler.schedule(wallpaperChangeJob);
            String scheduledMessage = res.getString(R.string.periodic_change_scheduled);
            Toast.makeText(context, scheduledMessage, Toast.LENGTH_SHORT).show();
        }
    }
}
 
开发者ID:danielgimenes,项目名称:NasaPic,代码行数:25,代码来源:PeriodicWallpaperChangeService.java

示例15: onReceive

import android.app.job.JobScheduler; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    JobScheduler jobScheduler =
            (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    // If there are not pending jobs. Create a sync job and schedule it.
    List<JobInfo> pendingJobs = jobScheduler.getAllPendingJobs();
    if (pendingJobs.isEmpty()) {
        String inputId = context.getSharedPreferences(EpgSyncJobService.PREFERENCE_EPG_SYNC,
                Context.MODE_PRIVATE).getString(EpgSyncJobService.BUNDLE_KEY_INPUT_ID, null);
        if (inputId != null) {
            // Set up periodic sync only when input has set up.
            EpgSyncJobService.setUpPeriodicSync(context, inputId,
                    new ComponentName(context, SampleJobService.class));
        }
        return;
    }
    // On L/L-MR1, reschedule the pending jobs.
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
        for (JobInfo job : pendingJobs) {
            if (job.isPersisted()) {
                jobScheduler.schedule(job);
            }
        }
    }
}
 
开发者ID:googlesamples,项目名称:androidtv-sample-inputs,代码行数:26,代码来源:RichBootReceiver.java


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