本文整理汇总了Java中com.firebase.jobdispatcher.FirebaseJobDispatcher.schedule方法的典型用法代码示例。如果您正苦于以下问题:Java FirebaseJobDispatcher.schedule方法的具体用法?Java FirebaseJobDispatcher.schedule怎么用?Java FirebaseJobDispatcher.schedule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.firebase.jobdispatcher.FirebaseJobDispatcher
的用法示例。
在下文中一共展示了FirebaseJobDispatcher.schedule方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scheduleJob
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入方法依赖的package包/类
private static boolean scheduleJob(Context context) {
FirebaseJobDispatcher dispatcher = getDispatcher(context);
Job job = dispatcher.newJobBuilder()
.setService(UploadService.class)
.setTag(context.getPackageName() + ".uploadqueue")
.setConstraints(Constraint.ON_ANY_NETWORK)
.setTrigger(Trigger.NOW)
.setLifetime(Lifetime.FOREVER)
.setRecurring(false)
.setReplaceCurrent(true)
.build();
int result = dispatcher.schedule(job);
if (result == FirebaseJobDispatcher.SCHEDULE_RESULT_SUCCESS) {
Logger.v("Job scheduled");
return true;
} else {
Logger.v("Job not scheduled");
return false;
}
}
示例2: scheduleFirebaseJobDispatcherSync
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入方法依赖的package包/类
static void scheduleFirebaseJobDispatcherSync(@NonNull final Context context) {
Driver driver = new GooglePlayDriver(context);
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);
/* Create the Job to periodically sync Sunshine */
Job syncSunshineJob = dispatcher.newJobBuilder()
.setService(NewsFirebaseJobService.class)
.setTag(NEWS_SYNC_TAG)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setLifetime(Lifetime.FOREVER)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(
REMINDER_INTERVAL_SECONDS,
REMINDER_INTERVAL_SECONDS + SYNC_FLEXTIME_SECONDS))
.setReplaceCurrent(true)
.build();
dispatcher.schedule(syncSunshineJob);
}
示例3: getNewLevelsSetup
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入方法依赖的package包/类
synchronized public static void getNewLevelsSetup(@NonNull final Context context) {
if (sInitialized){
return;
}
Driver driver = new GooglePlayDriver(context);
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);
/* Create the Job to periodically create reminders to drink water */
Job constraintReminderJob = dispatcher.newJobBuilder()
/* The Service that will be used to write to preferences */
.setService(GetLastStatusJobService.class)
/* Set the tag used to identify this Job. */
.setTag(SCHEDULER_JOB_TAG)
/* Live forever */
.setLifetime(Lifetime.FOREVER)
/* We want these reminders to continuously happen, so we tell this Job to recur. */
.setRecurring(true)
/* Trigger */
.setTrigger(Trigger.executionWindow(
REMINDER_INTERVAL_SECONDS,
SYNC_FLEXTIME_SECONDS))
/*
* If a Job with the tag with provided already exists, this new job will replace
* the old one.
*/
.setReplaceCurrent(true)
/* Once the Job is ready, call the builder's build method to return the Job */
.build();
/* Schedule the Job with the dispatcher */
dispatcher.schedule(constraintReminderJob);
/* The job has been initialized */
sInitialized = true;
}
示例4: scheduleChargingReminder
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入方法依赖的package包/类
synchronized public static void scheduleChargingReminder(@NonNull final Context context) {
// COMPLETED (17) If the job has already been initialized, return
if (sInitialized) return;
// COMPLETED (18) Create a new GooglePlayDriver
Driver driver = new GooglePlayDriver(context);
// COMPLETED (19) Create a new FirebaseJobDispatcher with the driver
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);
// COMPLETED (20) Use FirebaseJobDispatcher's newJobBuilder method to build a job which:
// - has WaterReminderFirebaseJobService as it's service
// - has the tag REMINDER_JOB_TAG
// - only triggers if the device is charging
// - has the lifetime of the job as forever
// - has the job recur
// - occurs every 15 minutes with a window of 15 minutes. You can do this using a
// setTrigger, passing in a Trigger.executionWindow
// - replaces the current job if it's already running
// Finally, you should build the job.
Job constraintReminderJob = dispatcher.newJobBuilder()
.setService(WaterReminderFirebaseJobService.class)
.setTag(REMINDER_JOB_TAG)
.setConstraints(Constraint.DEVICE_CHARGING)
.setLifetime(Lifetime.FOREVER)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(
REMINDER_INTERVAL_SECONDS,
REMINDER_INTERVAL_SECONDS + SYNC_FLEXTIME_SECONDS))
.setReplaceCurrent(true)
.build();
// COMPLETED (21) Use dispatcher's schedule method to schedule the job
dispatcher.schedule(constraintReminderJob);
// COMPLETED (22) Set sInitialized to true to mark that we're done setting up the job
sInitialized = true;
}
示例5: scheduleJob
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入方法依赖的package包/类
private void scheduleJob(Map<String, String> data) {
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
Bundle extras = new Bundle();
//Completa los extras con la información contenida en el mensaje
extras.putString("data", data.get("algunDato"));
Job myJob = dispatcher.newJobBuilder()
.setService(MyJobService.class)
.setTag("my-job-tag")
.setExtras(extras)
.build();
dispatcher.schedule(myJob);
}
示例6: scheduleJob
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入方法依赖的package包/类
/**
* Schedule a job using FirebaseJobDispatcher.
*/
private void scheduleJob() {
// [START dispatch_job]
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
Job myJob = dispatcher.newJobBuilder()
.setService(MyJobService.class)
.setTag("my-job-tag")
.build();
dispatcher.schedule(myJob);
// [END dispatch_job]
}
示例7: setup
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入方法依赖的package包/类
private static boolean setup(@NonNull final Context context, final int timeInSeconds, final boolean waitUnmeteredNetwork) {
if (!isBackupActive(context)) {
return false;
}
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
Job.Builder obBuilder = dispatcher.newJobBuilder()
// the JobService that will be called
.setService(DriveBackupService.class)
// uniquely identifies the job
.setTag(DriveBackupService.TAG)
// one-off job
.setRecurring(false)
// persist past a device reboot (requires boot receiver permission)
.setLifetime(Lifetime.FOREVER)
// overwrite an existing job with the same tag
.setReplaceCurrent(true)
// retry with exponential backoff
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR);
if (waitUnmeteredNetwork) {
// only run on an unmetered network
obBuilder.addConstraint(Constraint.ON_UNMETERED_NETWORK);
}
if (timeInSeconds >= 0) {
// Run after selected time and any time in one hour
obBuilder.setTrigger(Trigger.executionWindow(timeInSeconds, timeInSeconds + 1800));
} else {
obBuilder.setTrigger(Trigger.NOW);
}
return dispatcher.schedule(obBuilder.build()) == FirebaseJobDispatcher.SCHEDULE_RESULT_SUCCESS;
}
示例8: scheduleJob
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入方法依赖的package包/类
/**
* Schedule a job using FirebaseJobDispatcher. so if longer then 10 seconds, schedule the job.
*/
private void scheduleJob() {
// [START dispatch_job]
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
Job myJob = dispatcher.newJobBuilder()
.setService(MyJobService.class)
.setTag("my-job-tag")
.build();
dispatcher.schedule(myJob);
// [END dispatch_job]
}
示例9: scheduleFirebaseJobDispatcherSync
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入方法依赖的package包/类
/**
* Schedules a repeating sync of Sunshine's weather data using FirebaseJobDispatcher.
* @param context Context used to create the GooglePlayDriver that powers the
* FirebaseJobDispatcher
*/
static void scheduleFirebaseJobDispatcherSync(@NonNull final Context context) {
Driver driver = new GooglePlayDriver(context);
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);
/* Create the Job to periodically sync Sunshine */
Job syncSunshineJob = dispatcher.newJobBuilder()
/* The Service that will be used to sync Sunshine's data */
.setService(SunshineFirebaseJobService.class)
/* Set the UNIQUE tag used to identify this Job */
.setTag(SUNSHINE_SYNC_TAG)
/*
* Network constraints on which this Job should run. We choose to run on any
* network, but you can also choose to run only on un-metered networks or when the
* device is charging. It might be a good idea to include a preference for this,
* as some users may not want to download any data on their mobile plan. ($$$)
*/
.setConstraints(Constraint.ON_ANY_NETWORK)
/*
* setLifetime sets how long this job should persist. The options are to keep the
* Job "forever" or to have it die the next time the device boots up.
*/
.setLifetime(Lifetime.FOREVER)
/*
* We want Sunshine's weather data to stay up to date, so we tell this Job to recur.
*/
.setRecurring(true)
/*
* We want the weather data to be synced every 3 to 4 hours. The first argument for
* Trigger's static executionWindow method is the start of the time frame when the
* sync should be performed. The second argument is the latest point in time at
* which the data should be synced. Please note that this end time is not
* guaranteed, but is more of a guideline for FirebaseJobDispatcher to go off of.
*/
.setTrigger(Trigger.executionWindow(
SYNC_INTERVAL_SECONDS,
SYNC_INTERVAL_SECONDS + SYNC_FLEXTIME_SECONDS))
/*
* If a Job with the tag with provided already exists, this new job will replace
* the old one.
*/
.setReplaceCurrent(true)
/* Once the Job is ready, call the builder's build method to return the Job */
.build();
/* Schedule the Job with the dispatcher */
dispatcher.schedule(syncSunshineJob);
}
示例10: scheduleChargingReminder
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入方法依赖的package包/类
synchronized public static void scheduleChargingReminder(@NonNull final Context context) {
if (sInitialized) return;
Driver driver = new GooglePlayDriver(context);
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);
/* Create the Job to periodically create reminders to drink water */
Job constraintReminderJob = dispatcher.newJobBuilder()
/* The Service that will be used to write to preferences */
.setService(WaterReminderFirebaseJobService.class)
/*
* Set the UNIQUE tag used to identify this Job.
*/
.setTag(REMINDER_JOB_TAG)
/*
* Network constraints on which this Job should run. In this app, we're using the
* device charging constraint so that the job only executes if the device is
* charging.
*
* In a normal app, it might be a good idea to include a preference for this,
* as different users may have different preferences on when you should be
* syncing your application's data.
*/
.setConstraints(Constraint.DEVICE_CHARGING)
/*
* setLifetime sets how long this job should persist. The options are to keep the
* Job "forever" or to have it die the next time the device boots up.
*/
.setLifetime(Lifetime.FOREVER)
/*
* We want these reminders to continuously happen, so we tell this Job to recur.
*/
.setRecurring(true)
/*
* We want the reminders to happen every 15 minutes or so. The first argument for
* Trigger class's static executionWindow method is the start of the time frame
* when the
* job should be performed. The second argument is the latest point in time at
* which the data should be synced. Please note that this end time is not
* guaranteed, but is more of a guideline for FirebaseJobDispatcher to go off of.
*/
.setTrigger(Trigger.executionWindow(
REMINDER_INTERVAL_SECONDS,
REMINDER_INTERVAL_SECONDS + SYNC_FLEXTIME_SECONDS))
/*
* If a Job with the tag with provided already exists, this new job will replace
* the old one.
*/
.setReplaceCurrent(true)
/* Once the Job is ready, call the builder's build method to return the Job */
.build();
/* Schedule the Job with the dispatcher */
dispatcher.schedule(constraintReminderJob);
/* The job has been initialized */
sInitialized = true;
}
示例11: scheduleFirebaseJobDispatcherSync
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入方法依赖的package包/类
/**
* Schedules a repeating sync of Sunshine's weather data using FirebaseJobDispatcher.
*
* @param context Context used to create the GooglePlayDriver that powers the
* FirebaseJobDispatcher
*/
static void scheduleFirebaseJobDispatcherSync(@NonNull final Context context) {
Driver driver = new GooglePlayDriver(context);
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);
/* Create the Job to periodically sync Sunshine */
Job syncSunshineJob = dispatcher.newJobBuilder()
/* The Service that will be used to sync Sunshine's data */
.setService(SunshineFirebaseJobService.class)
/* Set the UNIQUE tag used to identify this Job */
.setTag(SUNSHINE_SYNC_TAG)
/*
* Network constraints on which this Job should run. We choose to run on any
* network, but you can also choose to run only on un-metered networks or when the
* device is charging. It might be a good idea to include a preference for this,
* as some users may not want to download any data on their mobile plan. ($$$)
*/
.setConstraints(Constraint.ON_ANY_NETWORK)
/*
* setLifetime sets how long this job should persist. The options are to keep the
* Job "forever" or to have it die the next time the device boots up.
*/
.setLifetime(Lifetime.FOREVER)
/*
* We want Sunshine's weather data to stay up to date, so we tell this Job to recur.
*/
.setRecurring(true)
/*
* We want the weather data to be synced every 3 to 4 hours. The first argument for
* Trigger's static executionWindow method is the start of the time frame when the
* sync should be performed. The second argument is the latest point in time at
* which the data should be synced. Please note that this end time is not
* guaranteed, but is more of a guideline for FirebaseJobDispatcher to go off of.
*/
.setTrigger(Trigger.executionWindow(
SYNC_INTERVAL_SECONDS,
SYNC_INTERVAL_SECONDS + SYNC_FLEXTIME_SECONDS))
/*
* If a Job with the tag with provided already exists, this new job will replace
* the old one.
*/
.setReplaceCurrent(true)
/* Once the Job is ready, call the builder's build method to return the Job */
.build();
/* Schedule the Job with the dispatcher */
dispatcher.schedule(syncSunshineJob);
}