本文整理汇总了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");
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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());
}
}
示例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();
}
示例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);
}