當前位置: 首頁>>代碼示例>>Java>>正文


Java JobInfo類代碼示例

本文整理匯總了Java中android.app.job.JobInfo的典型用法代碼示例。如果您正苦於以下問題:Java JobInfo類的具體用法?Java JobInfo怎麽用?Java JobInfo使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JobInfo類屬於android.app.job包,在下文中一共展示了JobInfo類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onSharedPreferenceChanged

import android.app.job.JobInfo; //導入依賴的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: requestSync

import android.app.job.JobInfo; //導入依賴的package包/類
public static void requestSync(Context context, String inputId, boolean currentProgramOnly) {
    PersistableBundle pBundle = new PersistableBundle();
    pBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    pBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    pBundle.putString(SyncJobService.BUNDLE_KEY_INPUT_ID, inputId);
    pBundle.putBoolean(SyncJobService.BUNDLE_KEY_CURRENT_PROGRAM_ONLY, currentProgramOnly);
    JobInfo.Builder builder = new JobInfo.Builder(REQUEST_SYNC_JOB_ID,
            new ComponentName(context, SyncJobService.class));
    JobInfo jobInfo = builder
            .setExtras(pBundle)
            .setOverrideDeadline(SyncJobService.OVERRIDE_DEADLINE_MILLIS)
            .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
            .build();
    scheduleJob(context, jobInfo);
    Intent intent = new Intent(SyncJobService.ACTION_SYNC_STATUS_CHANGED);
    intent.putExtra(SyncJobService.BUNDLE_KEY_INPUT_ID, inputId);
    intent.putExtra(SyncJobService.SYNC_STATUS, SyncJobService.SYNC_STARTED);
    LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
 
開發者ID:nejtv,項目名稱:androidtv-sample,代碼行數:20,代碼來源:SyncUtils.java

示例3: onReceive

import android.app.job.JobInfo; //導入依賴的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

示例4: scheduleAddWatchNextRequest

import android.app.job.JobInfo; //導入依賴的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

示例5: schedule

import android.app.job.JobInfo; //導入依賴的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

示例6: onCreate

import android.app.job.JobInfo; //導入依賴的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

示例7: testProcessOnePacket

import android.app.job.JobInfo; //導入依賴的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: schedule

import android.app.job.JobInfo; //導入依賴的package包/類
@Override
public int schedule(JobInfo job) throws RemoteException {
    int vuid = VBinder.getCallingUid();
    int id = job.getId();
    ComponentName service = job.getService();
    JobId jobId = new JobId(vuid, service.getPackageName(), id);
    JobConfig config = mJobStore.get(jobId);
    if (config == null) {
        config = new JobConfig(mGlobalJobId++, service.getClassName(), job.getExtras());
        mJobStore.put(jobId, config);
    } else {
        config.serviceName = service.getClassName();
        config.extras = job.getExtras();
    }
    saveJobs();
    mirror.android.app.job.JobInfo.jobId.set(job, config.virtualJobId);
    mirror.android.app.job.JobInfo.service.set(job, mJobProxyComponent);
    return mScheduler.schedule(job);
}
 
開發者ID:7763sea,項目名稱:VirtualHook,代碼行數:20,代碼來源:VJobSchedulerService.java

示例9: testStart

import android.app.job.JobInfo; //導入依賴的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

示例10: schedule

import android.app.job.JobInfo; //導入依賴的package包/類
public void schedule(int time, boolean startOnBoot) {
    if (mAlarm == null) {
        JobInfo.Builder job = new JobInfo.Builder(1, new ComponentName(mContext, NotificationsJS.class));
        PersistableBundle pb = new PersistableBundle();
        pb.putInt("JobSyncTime", time);
        job.setPersisted(startOnBoot)
                .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                .setMinimumLatency(time)
                .setExtras(pb);
        if (connected())
            if (syncExact == 1)
                job.setOverrideDeadline(time);
            else
                job.setOverrideDeadline(time * 2);
        mJobScheduler.schedule(job.build());
        Log.i("MFB_Scheduler", "JobScheduler started");
    } else {
        syncTime = time;
        receiver = new Receiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
        mContext.getPackageManager().setComponentEnabledSetting(new ComponentName(mContext, Receiver.class), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
        mContext.registerReceiver(receiver, filter);
        Log.i("MFB_Scheduler", "AlarmManager started");
    }
}
 
開發者ID:ZeeRooo,項目名稱:MaterialFBook,代碼行數:27,代碼來源:Scheduler.java

示例11: schedule

import android.app.job.JobInfo; //導入依賴的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

示例12: startPolling

import android.app.job.JobInfo; //導入依賴的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

示例13: onBindViewHolder

import android.app.job.JobInfo; //導入依賴的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

示例14: schedulePeriodic

import android.app.job.JobInfo; //導入依賴的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

示例15: syncJob

import android.app.job.JobInfo; //導入依賴的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


注:本文中的android.app.job.JobInfo類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。