当前位置: 首页>>代码示例>>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;未经允许,请勿转载。