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


Java JobScheduler类代码示例

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


JobScheduler类属于android.app.job包,在下文中一共展示了JobScheduler类的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: 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

示例7: testProcessOnePacket

import android.app.job.JobScheduler; //导入依赖的package包/类
@Test(timeout = 5000)
public void testProcessOnePacket() throws Exception {
    DataPacket dataPacket = new ByteArrayDataPacket(Collections.singletonMap("id", "testId"), "testPayload".getBytes(Charsets.UTF_8));
    queuedSiteToSiteClientConfig.createQueuedClient(context).enqueue(dataPacket);

    mockNiFiS2SServer.enqueueSiteToSitePeers(Collections.singletonList(peer));
    String transactionPath = mockNiFiS2SServer.enqueuCreateTransaction(portIdentifier, transactionIdentifier, 30);
    mockNiFiS2SServer.enqueuDataPackets(transactionPath, Collections.singletonList(dataPacket), queuedSiteToSiteClientConfig);
    mockNiFiS2SServer.enqueueTransactionComplete(transactionPath, 2, ResponseCode.CONFIRM_TRANSACTION, ResponseCode.CONFIRM_TRANSACTION);

    JobInfo.Builder processJobInfoBuilder = SiteToSiteJobService.createProcessJobInfoBuilder(context, 1, queuedSiteToSiteClientConfig, parcelableQueuedOperationResultCallback);
    processJobInfoBuilder.setOverrideDeadline(0);
    JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    assertEquals(JobScheduler.RESULT_SUCCESS, jobScheduler.schedule(processJobInfoBuilder.build()));
    assertEquals(1, parcelableQueuedOperationResultCallback.getInvocations().size());
    SiteToSiteDBTestUtil.assertNoQueuedPackets(siteToSiteDB);
    mockNiFiS2SServer.verifyAssertions();
}
 
开发者ID:hortonworks,项目名称:nifi-android-s2s,代码行数:19,代码来源:SiteToSiteJobServiceTest.java

示例8: testStart

import android.app.job.JobScheduler; //导入依赖的package包/类
@Test
public void testStart() {
    Context context = InstrumentationRegistry.getTargetContext();
    QuickPeriodicJobScheduler qpjs = new QuickPeriodicJobScheduler(context);
    qpjs.start(2, 30000l);

    SystemClock.sleep(1000);

    JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    List<JobInfo> jobInfoList = jobScheduler.getAllPendingJobs();
    JobInfo jobInfo = null;
    for(JobInfo job : jobInfoList) {
        if(job.getId() == 2) {
            jobInfo = job;
        }
    }

    Assert.assertEquals(jobInfo.getMaxExecutionDelayMillis(), 30000l);
    Assert.assertEquals(jobInfo.getMinLatencyMillis(), 30000l);
    Assert.assertEquals(jobInfo.getId(), 2);
    Assert.assertEquals(jobInfo.getExtras().getLong("interval"), 30000l);
    Assert.assertNotNull(jobInfo);
}
 
开发者ID:simplymadeapps,项目名称:QuickPeriodicJobScheduler,代码行数:24,代码来源:InstrumentedTests.java

示例9: schedule

import android.app.job.JobScheduler; //导入依赖的package包/类
public static void schedule(Context context) {

        SharedPreferences settings = AppSettings.getSharedPreferences(context);
        int notificationsFrequency = AppSettings.Notifications.getNotificationsFrequency(settings);

        ComponentName component = new ComponentName(context, NotificationsJobService.class);
        JobInfo.Builder builder = new JobInfo.Builder(JOB_ID, component)
                .setPeriodic(60000 * notificationsFrequency);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
            builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_NOT_ROAMING);
        else
            builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);

        JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
        jobScheduler.schedule(builder.build());
    }
 
开发者ID:pvarry,项目名称:intra42,代码行数:17,代码来源:NotificationsJobService.java

示例10: 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

示例11: onCreate

import android.app.job.JobScheduler; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.job_list_activity);
    RecyclerView rv = (RecyclerView)findViewById(R.id.jobList);

    // Set the recycler view layout
    LinearLayoutManager llm = new LinearLayoutManager(this);
    rv.setLayoutManager(llm);

    initList();

    Button cancelAllBut = (Button)findViewById(R.id.cancelAllBut);
    cancelAllBut.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            JobScheduler jobScheduler = (JobScheduler)getSystemService(JOB_SCHEDULER_SERVICE);
            jobScheduler.cancelAll();
            initList();
            Toast.makeText(JobListActivity.this,
                    "Cancelling all the pending jobs",
                    Toast.LENGTH_LONG).show();
        }
    });
}
 
开发者ID:PacktPublishing,项目名称:Asynchronous-Android-Programming,代码行数:26,代码来源:JobListActivity.java

示例12: onBindViewHolder

import android.app.job.JobScheduler; //导入依赖的package包/类
@Override
public void onBindViewHolder(JobListRecyclerAdapter.JobViewHolder holder, int position) {

    final JobInfo ji= mJobList.get(position);
    holder.jobId.setText(Integer.toString(ji.getId()));
    holder.serviceName.setText(ji.getService().getClassName());
    holder.stopBut.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            JobScheduler jobScheduler = (JobScheduler)mContext.getSystemService(mContext.JOB_SCHEDULER_SERVICE);
            jobScheduler.cancel(ji.getId());
            Log.i("JobList", "Stopping the job "+ji.getId());
            Toast.makeText(mContext,
                    "Canceling the job "+ji.getId(),
                    Toast.LENGTH_LONG).show();
            mContext.initList();
        }
    });
}
 
开发者ID:PacktPublishing,项目名称:Asynchronous-Android-Programming,代码行数:20,代码来源:JobListRecyclerAdapter.java

示例13: 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

示例14: 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

示例15: 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");
    }
}
 
开发者ID:infobip,项目名称:mobile-messaging-sdk-android,代码行数:20,代码来源:MobileMessagingJobService.java


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