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


Java JobInfo.getId方法代碼示例

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


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

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

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

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

示例4: maybeRetryDownloadDueToGainedConnectivity

import android.app.job.JobInfo; //導入方法依賴的package包/類
public static Intent maybeRetryDownloadDueToGainedConnectivity(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
        List<JobInfo> pendingJobs = jobScheduler.getAllPendingJobs();
        for (JobInfo pendingJob : pendingJobs) {
            if (pendingJob.getId() == LOAD_ARTWORK_JOB_ID) {
                return TaskQueueService.getDownloadCurrentArtworkIntent(context);
            }
        }
        return null;
    }
    return (PreferenceManager.getDefaultSharedPreferences(context)
            .getInt(PREF_ARTWORK_DOWNLOAD_ATTEMPT, 0) > 0)
            ? TaskQueueService.getDownloadCurrentArtworkIntent(context)
            : null;
}
 
開發者ID:romannurik,項目名稱:muzei,代碼行數:17,代碼來源:TaskQueueService.java

示例5: createQuoteDownloadJob

import android.app.job.JobInfo; //導入方法依賴的package包/類
public static void createQuoteDownloadJob(Context context, boolean recreate) {
    Xlog.d(TAG, "JobUtils#createQuoteDownloadJob called, recreate == %s", recreate);

    // Instead of canceling the job whenever we disconnect from the
    // internet, we wait until the job executes. Upon execution, we re-check
    // the condition -- if network connectivity has been restored, we just
    // proceed as normal, otherwise, we do not reschedule the task until
    // we receive a network connectivity event.
    if (!shouldRefreshQuote(context)) {
        Xlog.d(TAG, "Should not create job under current conditions, ignoring");
        return;
    }

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

    // If we're not forcing a job refresh (e.g. when a setting changes),
    // ignore the request if the job already exists
    if (!recreate) {
        for (JobInfo job : scheduler.getAllPendingJobs()) {
            if (job.getId() == JOB_ID) {
                Xlog.d(TAG, "Job already exists and recreate == false, ignoring");
                return;
            }
        }
    }

    int delay = getUpdateDelay(context);
    int networkType = getNetworkType(context);
    JobInfo jobInfo = new JobInfo.Builder(JOB_ID, new ComponentName(context, QuoteDownloaderService.class))
        .setMinimumLatency(delay * 1000)
        .setOverrideDeadline(delay * 1200) // Good balance between battery life and time accuracy
        .setRequiredNetworkType(networkType)
        .build();
    scheduler.schedule(jobInfo);

    Xlog.d(TAG, "Scheduled quote download job with delay: %d", delay);
}
 
開發者ID:apsun,項目名稱:QuoteLock,代碼行數:38,代碼來源:JobUtils.java

示例6: isBeenScheduled

import android.app.job.JobInfo; //導入方法依賴的package包/類
@TargetApi(21)
public static boolean isBeenScheduled(int JOB_ID, Context context){
    JobScheduler scheduler = (JobScheduler)
            context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    boolean hasBeenScheduled = false;
    for (JobInfo jobInfo : scheduler.getAllPendingJobs()){
        if (jobInfo.getId() == JOB_ID) {
            hasBeenScheduled = true;
        }
    }
    return hasBeenScheduled;
}
 
開發者ID:shier2nd,項目名稱:LatestDiscounts,代碼行數:13,代碼來源:PollJobService.java

示例7: getScheduledJob

import android.app.job.JobInfo; //導入方法依賴的package包/類
@Nullable
private static JobInfo getScheduledJob(Context context) {
    for (JobInfo jobInfo : getJobScheduler(context).getAllPendingJobs()) {
        if (jobInfo.getId() == JOB_ID) {
            return jobInfo;
        }
    }
    return null;
}
 
開發者ID:ranmocy,項目名稱:MonkeyTree,代碼行數:10,代碼來源:MonkeyService.java

示例8: isJobInfoScheduled

import android.app.job.JobInfo; //導入方法依賴的package包/類
@SuppressWarnings("SimplifiableIfStatement")
protected boolean isJobInfoScheduled(@Nullable JobInfo info, @NonNull JobRequest request) {
    boolean correctInfo = info != null && info.getId() == request.getJobId();
    if (!correctInfo) {
        return false;
    }
    return !request.isTransient() || TransientBundleCompat.isScheduled(mContext, request.getJobId());
}
 
開發者ID:evernote,項目名稱:android-job,代碼行數:9,代碼來源:JobProxy21.java

示例9: isMediaContentJobServiceRegistered

import android.app.job.JobInfo; //導入方法依賴的package包/類
/**
 * Method used to verify if the job service is registered.
 *
 * @param context Application context.
 * @return True if the service is registered.
 */
@TargetApi(Build.VERSION_CODES.N)
public boolean isMediaContentJobServiceRegistered(Context context) {
	JobScheduler js = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
	List<JobInfo> jobs = js != null ? js.getAllPendingJobs() : null;
	if (jobs != null && !jobs.isEmpty()) {
		for (JobInfo jobInfo : jobs) {
			if (jobInfo.getId() == MediaContentJobService.JOB_ID) {
				return true;
			}
		}
	}
	return false;
}
 
開發者ID:ciubex,項目名稱:dscautorename,代碼行數:20,代碼來源:DSCApplication.java

示例10: runKwotdServiceJob

import android.app.job.JobInfo; //導入方法依賴的package包/類
protected void runKwotdServiceJob(boolean isOneOffJob) {
  boolean jobAlreadyExists = false;
  JobScheduler scheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
  if (!isOneOffJob) {
    // Check if persisted job is already running.
    for (JobInfo jobInfo : scheduler.getAllPendingJobs()) {
      if (jobInfo.getId() == KWOTD_SERVICE_PERSISTED_JOB_ID) {
        // Log.d(TAG, "KWOTD job already exists.");
        jobAlreadyExists = true;
        break;
      }
    }
  }

  // Start job.
  if (!jobAlreadyExists) {
    JobInfo.Builder builder;

    if (isOneOffJob) {
      // A one-off request to the KWOTD server needs Internet access.
      ConnectivityManager cm =
          (ConnectivityManager) getBaseContext().getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
      if (activeNetwork == null || !activeNetwork.isConnectedOrConnecting()) {
        // Inform the user the fetch will happen when there is an Internet connection.
        Toast.makeText(
                this,
                getResources().getString(R.string.kwotd_requires_internet),
                Toast.LENGTH_LONG)
            .show();
      } else {
        // Inform the user operation is under way.
        Toast.makeText(
                this, getResources().getString(R.string.kwotd_fetching), Toast.LENGTH_SHORT)
            .show();
      }

      // Either way, schedule the job for when Internet access is available.
      builder =
          new JobInfo.Builder(
              KWOTD_SERVICE_ONE_OFF_JOB_ID, new ComponentName(this, KwotdService.class));
      builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);

    } else {
      // Set the job to run every 24 hours, during a window with network connectivity, and
      // exponentially back off if it fails with a delay of 1 hour. (Note that Android caps the
      // backoff at 5 hours, so this will retry at 1 hour, 2 hours, and 4 hours, before it
      // gives up.)
      builder =
          new JobInfo.Builder(
              KWOTD_SERVICE_PERSISTED_JOB_ID, new ComponentName(this, KwotdService.class));
      builder.setPeriodic(TimeUnit.HOURS.toMillis(24));
      builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
      builder.setBackoffCriteria(TimeUnit.HOURS.toMillis(1), JobInfo.BACKOFF_POLICY_EXPONENTIAL);
      builder.setRequiresCharging(false);
      builder.setPersisted(true);
    }

    // Pass custom params to job.
    PersistableBundle extras = new PersistableBundle();
    extras.putBoolean(KwotdService.KEY_IS_ONE_OFF_JOB, isOneOffJob);
    builder.setExtras(extras);

    Log.d(TAG, "Scheduling KwotdService job, isOneOffJob: " + isOneOffJob);
    scheduler.schedule(builder.build());
  }
}
 
開發者ID:De7vID,項目名稱:klingon-assistant,代碼行數:68,代碼來源:BaseActivity.java

示例11: isJobInfoScheduled

import android.app.job.JobInfo; //導入方法依賴的package包/類
@Override
protected boolean isJobInfoScheduled(@Nullable JobInfo info, @NonNull JobRequest request) {
    return info != null && info.getId() == request.getJobId();
}
 
開發者ID:evernote,項目名稱:android-job,代碼行數:5,代碼來源:JobProxy26.java

示例12: schedule

import android.app.job.JobInfo; //導入方法依賴的package包/類
public boolean schedule() {
    final JobInfo jobInfo = mBuilder.build();
    mId = jobInfo.getId();
    return (SystemServices.jobScheduler().schedule(jobInfo) == JobScheduler.RESULT_SUCCESS);
}
 
開發者ID:shkschneider,項目名稱:android_Skeleton,代碼行數:6,代碼來源:JobManager.java


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