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


Java JobScheduler.RESULT_SUCCESS屬性代碼示例

本文整理匯總了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");
    }
}
 
開發者ID:Applications-Development,項目名稱:SimpleRssReader,代碼行數:24,代碼來源:PeriodicJob.java

示例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!");
    }

}
 
開發者ID:jkozh,項目名稱:stockhawk,代碼行數:23,代碼來源:QuoteSyncJob.java

示例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");
    }
}
 
開發者ID:infobip,項目名稱:mobile-messaging-sdk-android,代碼行數:19,代碼來源:MobileMessagingJobService.java

示例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");
    }
}
 
開發者ID:kebernet,項目名稱:shortyz,代碼行數:22,代碼來源:BackgroundDownloadService.java

示例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;
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:22,代碼來源:BackgroundTaskSchedulerJobService.java

示例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();
    }
}
 
開發者ID:PacktPublishing,項目名稱:Asynchronous-Android-Programming,代碼行數:35,代碼來源:AccountInfoActivity.java

示例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;
}
 
開發者ID:julian-klode,項目名稱:dns66,代碼行數:35,代碼來源:RuleDatabaseUpdateJobService.java

示例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);
	}
}
 
開發者ID:ciubex,項目名稱:dscautorename,代碼行數:15,代碼來源:DSCApplication.java

示例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();
        }
    }
 
開發者ID:twotoasters,項目名稱:toastdroid,代碼行數:15,代碼來源:MainActivity.java

示例10: schedule

@Override
public int schedule(JobInfo job) {
    int result = jobScheduler.schedule(toPlatformJob(job).build());
    return result == JobScheduler.RESULT_SUCCESS ? RESULT_SUCCESS : RESULT_FAILURE;
}
 
開發者ID:Doist,項目名稱:JobSchedulerCompat,代碼行數:5,代碼來源:JobSchedulerSchedulerV21.java

示例11: scheduleResultToString

protected static String scheduleResultToString(int scheduleResult) {
    return scheduleResult == JobScheduler.RESULT_SUCCESS ? "success" : "failure";
}
 
開發者ID:evernote,項目名稱:android-job,代碼行數:3,代碼來源:JobProxy21.java

示例12: schedule

public boolean schedule() {
    final JobInfo jobInfo = mBuilder.build();
    mId = jobInfo.getId();
    return (SystemServices.jobScheduler().schedule(jobInfo) == JobScheduler.RESULT_SUCCESS);
}
 
開發者ID:shkschneider,項目名稱:android_Skeleton,代碼行數:5,代碼來源:JobManager.java


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