本文整理匯總了Java中android.app.job.JobScheduler.RESULT_SUCCESS屬性的典型用法代碼示例。如果您正苦於以下問題:Java JobScheduler.RESULT_SUCCESS屬性的具體用法?Java JobScheduler.RESULT_SUCCESS怎麽用?Java JobScheduler.RESULT_SUCCESS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.app.job.JobScheduler
的用法示例。
在下文中一共展示了JobScheduler.RESULT_SUCCESS屬性的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: schedule
@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: schedulePeriodic
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!");
}
}
示例3: registerForNetworkAvailability
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");
}
}
示例4: scheduleJob
private static void scheduleJob(Context context) {
JobScheduler scheduler =
(JobScheduler)context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
JobInfo info = getJobInfo(
preferences.getBoolean("backgroundDownloadRequireUnmetered", true),
preferences.getBoolean("backgroundDownloadAllowRoaming", false),
preferences.getBoolean("backgroundDownloadRequireCharging", false));
LOGGER.info("Scheduling background download job: " + info);
int result = scheduler.schedule(info);
if (result == JobScheduler.RESULT_SUCCESS) {
LOGGER.info("Successfully scheduled background downloads");
} else {
LOGGER.log(Level.WARNING, "Unable to schedule background downloads");
}
}
示例5: schedule
@Override
public boolean schedule(Context context, TaskInfo taskInfo) {
ThreadUtils.assertOnUiThread();
if (!BackgroundTaskScheduler.hasParameterlessPublicConstructor(
taskInfo.getBackgroundTaskClass())) {
Log.e(TAG, "BackgroundTask " + taskInfo.getBackgroundTaskClass()
+ " has no parameterless public constructor.");
return false;
}
JobInfo jobInfo = createJobInfoFromTaskInfo(context, taskInfo);
JobScheduler jobScheduler =
(JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
if (taskInfo.shouldUpdateCurrent()) {
jobScheduler.cancel(taskInfo.getTaskId());
}
int result = jobScheduler.schedule(jobInfo);
return result == JobScheduler.RESULT_SUCCESS;
}
示例6: setupJob
void setupJob(boolean isPeriodic) {
PersistableBundle bundle = new PersistableBundle();
bundle.putString(SyncTask.SYNC_FILE_KEY, SYNC_FILE);
bundle.putString(SyncTask.SYNC_PATH_KEY, SYNC_PATH);
ComponentName serviceName = new ComponentName(this, AccountBackupJobService.class);
JobInfo.Builder builder = null;
if (isPeriodic) {
builder = new JobInfo.Builder(SYNC_PER_JOB_ID, serviceName);
builder.setPersisted(true);
builder.setPeriodic(TimeUnit.HOURS.toMillis(12L));
} else {
builder = new JobInfo.Builder(SYNC_JOB_ID, serviceName);
builder.setOverrideDeadline(TimeUnit.HOURS.toMillis(8L));
}
builder.setRequiresCharging(true)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
.setRequiresDeviceIdle(true)
.setExtras(bundle);
JobScheduler jobScheduler = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE);
int result = jobScheduler.schedule(builder.build());
if ( result != JobScheduler.RESULT_SUCCESS) {
Log.i("SharedPref", "Failed to Setup a Job");
Toast.makeText(AccountInfoActivity.this,
"Failed to Setup a SharedPrefBack job",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(AccountInfoActivity.this,
"SharedPrefBack job successfully scheduled",
Toast.LENGTH_SHORT).show();
}
}
示例7: scheduleOrCancel
/**
* Schedules or cancels the job, depending on the configuration
*
* @return true if the job could be scheduled.
*/
public static boolean scheduleOrCancel(Context context, Configuration configuration) {
JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
if (!configuration.hosts.automaticRefresh) {
Log.d(TAG, "scheduleOrCancel: Cancelling Job");
scheduler.cancel(JOB_ID);
return true;
}
Log.d(TAG, "scheduleOrCancel: Scheduling Job");
ComponentName serviceName = new ComponentName(context, RuleDatabaseUpdateJobService.class);
JobInfo jobInfo = new JobInfo.Builder(JOB_ID, serviceName)
.setRequiresCharging(true)
.setRequiresDeviceIdle(true)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
.setPersisted(true)
.setPeriodic(TimeUnit.DAYS.toMillis(1))
.build();
int result = scheduler.schedule(jobInfo);
if (result == JobScheduler.RESULT_SUCCESS)
Log.d(TAG, "Job scheduled");
else
Log.d(TAG, "Job not scheduled");
return result == JobScheduler.RESULT_SUCCESS;
}
示例8: scheduleMediaContentJobService
/**
* Method used to schedule this job service.
*
* @param context The application context.
*/
@TargetApi(Build.VERSION_CODES.N)
public void scheduleMediaContentJobService(Context context, JobInfo jobInfo) {
JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
int result = scheduler.schedule(jobInfo);
if (result == JobScheduler.RESULT_SUCCESS) {
logD(TAG, "JobScheduler OK");
} else {
logD(TAG, "JobScheduler fails: " + result);
}
}
示例9: scheduleJob
private void scheduleJob() {
ComponentName serviceName = new ComponentName(this, MyJobService.class);
JobInfo jobInfo = new JobInfo.Builder(JOB_ID, serviceName)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
.setRequiresDeviceIdle(true)
.setRequiresCharging(true)
// .setOverrideDeadline(400) // Remove comment for faster testing.
.build();
JobScheduler scheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
int result = scheduler.schedule(jobInfo);
if (result == JobScheduler.RESULT_SUCCESS) {
Toast.makeText(this, R.string.job_scheduled_successfully, Toast.LENGTH_LONG).show();
}
}
示例10: schedule
@Override
public int schedule(JobInfo job) {
int result = jobScheduler.schedule(toPlatformJob(job).build());
return result == JobScheduler.RESULT_SUCCESS ? RESULT_SUCCESS : RESULT_FAILURE;
}
示例11: scheduleResultToString
protected static String scheduleResultToString(int scheduleResult) {
return scheduleResult == JobScheduler.RESULT_SUCCESS ? "success" : "failure";
}
示例12: schedule
public boolean schedule() {
final JobInfo jobInfo = mBuilder.build();
mId = jobInfo.getId();
return (SystemServices.jobScheduler().schedule(jobInfo) == JobScheduler.RESULT_SUCCESS);
}