本文整理汇总了Java中com.firebase.jobdispatcher.FirebaseJobDispatcher类的典型用法代码示例。如果您正苦于以下问题:Java FirebaseJobDispatcher类的具体用法?Java FirebaseJobDispatcher怎么用?Java FirebaseJobDispatcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FirebaseJobDispatcher类属于com.firebase.jobdispatcher包,在下文中一共展示了FirebaseJobDispatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入依赖的package包/类
public void init (FirebaseApp firebaseApp) {
mFirebaseApp = firebaseApp;
String token = getFirebaseMessagingToken();
dispatcher =
new FirebaseJobDispatcher(new GooglePlayDriver(activity.getApplicationContext()));
dispatcher.cancel("firebase-notify-in-time-UID");
Utils.d("Firebase Cloud messaging token: " + token);
// Perform task here..!
if (KeyValueStorage.getValue("notification_complete_task") != "0") {
try {
JSONObject obj =
new JSONObject(KeyValueStorage.getValue("notification_task_data"));
Dictionary data = new Dictionary();
Iterator<String> iterator = obj.keys();
while (iterator.hasNext()) {
String key = iterator.next();
Object value = obj.opt(key);
if (value != null) {
data.put(key, value);
}
}
Utils.callScriptCallback(
KeyValueStorage.getValue("notification_complete_task"),
"Notification", "TaskComplete", data);
} catch (JSONException e) {
}
KeyValueStorage.setValue("notification_complete_task", "0");
}
}
示例2: setupCinemaListUpdates
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入依赖的package包/类
private void setupCinemaListUpdates() {
long lastUpdated = getSharedPreferences("settings", MODE_PRIVATE).getLong("cinemasUpdated", -1);
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
if(lastUpdated < (System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7))) {
// It's been more than a week since the last update, so setup/reset job because it should have run by now
Job updateJob = dispatcher.newJobBuilder()
.setService(CinemaUpdateJob.class)
.setTag("cinemasListUpdate")
.setRecurring(true)
.setLifetime(Lifetime.FOREVER)
.setTrigger(Trigger.executionWindow(0, (int) TimeUnit.DAYS.toSeconds(7)))
.setReplaceCurrent(true)
.build();
dispatcher.mustSchedule(updateJob);
}
// Also run immediately if the list has never been updated
if(lastUpdated == -1) {
dispatcher.mustSchedule(CinemaUpdateJob.getJobToUpdateImmediately(dispatcher));
}
}
示例3: 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;
}
}
示例4: syncImmediately
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入依赖的package包/类
synchronized public static void syncImmediately(Context context, String tag) {
Timber.d("Scheduling a immediate sync");
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver
(context));
Bundle bundle = new Bundle();
Job myJob = dispatcher.newJobBuilder()
.setService(QuoteJobService.class)
.setTag(tag)
.setExtras(bundle)
.setRecurring(false)
.setTrigger(Trigger.executionWindow(0, 0))
.setLifetime(Lifetime.UNTIL_NEXT_BOOT)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
.setReplaceCurrent(true)
.build();
dispatcher.mustSchedule(myJob);
}
示例5: onSetupComplete
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入依赖的package包/类
@SuppressLint("ApplySharedPref")
private void onSetupComplete() {
//download whole leaderboards data asynchronously
new FetchLeaderBoardDataAsync(this).execute();
//schedule daily sync at 3:00 am local time
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
DateTime now = new DateTime();
DateTime tomorrow = now.plusDays(1).withTimeAtStartOfDay().plusHours(3);
int windowStart = Hours.hoursBetween(now, tomorrow).getHours() * 60 * 60;
Job synJob = dispatcher.newJobBuilder()
.setService(SyncScheduler.class)
.setTag(Constants.PERIODIC_SYNC_SCHEDULE_KEY)
.setReplaceCurrent(true)
.setTrigger(Trigger.executionWindow(windowStart, windowStart + 10))
.setConstraints(Constraint.ON_ANY_NETWORK)
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
.build();
dispatcher.mustSchedule(synJob);
sharedPreferences.edit().putBoolean(Constants.PREF_FIREBASE_SETUP, true).commit();
startActivity(new Intent(this, PreChecksActivity.class));
finish();
}
示例6: sendSyncObjects
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入依赖的package包/类
@WorkerThread
public static boolean sendSyncObjects(Context context, LinkedHashSet<SyncParam> syncParams) {
if(!NetworkUtil.isConnected(context)){
scheduleJob(context, SEND_SYNC_TAG);
return false;
}
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
dispatcher.cancel(SEND_SYNC_TAG);
if(syncParams == null){
Log.e("SyncService", "erro ao enviar syncParamns: null");
return false;
}
boolean result = true;
for(SyncParam syncParam : syncParams){
boolean sent = sendSyncObj(syncParam);
if(result) result = sent;
}
return result;
}
示例7: 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);
}
示例8: scheduleJob
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入依赖的package包/类
public static void scheduleJob(Context context, Message message) {
try {
Bundle bundle = new Bundle();
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
bundle.putString(MobiComKitConstants.AL_MESSAGE_KEY, message.getKeyString());
Class pushNotificationJobServiceClass = Class.forName("com.applozic.mobicomkit.uiwidgets.notification.PushNotificationJobService");
Job myJob = dispatcher.newJobBuilder()
.setService(pushNotificationJobServiceClass) // the JobService that will be called
.setTag(MobiComKitConstants.PUSH_NOTIFICATION_DISPATCHER) // uniquely identifies the job
.setRecurring(false)
.setTrigger(Trigger.executionWindow(0, 0))
.setReplaceCurrent(true)
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setExtras(bundle)
.build();
dispatcher.mustSchedule(myJob);
} catch (Exception e) {
e.printStackTrace();
}
}
示例9: scheduleImageService
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入依赖的package包/类
@Override
public void scheduleImageService(FirebaseJobDispatcher dispatcher) {
dispatcher
.newJobBuilder()
.setService(DownloadImageService.class)
.setTag(Configuration.JOB_ID_DOWNLOAD_IMAGE_SERVICE)
.setRecurring(false)
.setLifetime(Lifetime.FOREVER)
.setTrigger(Trigger.executionWindow(0, 3600))
.setReplaceCurrent(true)
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
.setConstraints(
Constraint.ON_UNMETERED_NETWORK,
Constraint.DEVICE_CHARGING
)
.build();
}
示例10: onStartJob
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入依赖的package包/类
@Override
public boolean onStartJob(JobParameters params) {
Log.inform("Sync Job request received");
dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(getBaseContext()));
switch (params.getTag()) {
case RESET_ALL_JOBS:
resetAllJobs();
break;
case SYNC_PREFERENCES:
syncPreferences();
break;
case SYNC_ROUTE_DATA:
syncRouteData();
break;
case SINGLE_ROUTE_SYNC:
syncRouteData();
break;
}
return false;
}
示例11: startRest
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入依赖的package包/类
void startRest(final Context context) {
new ResetRoutes(new OnFinish() {
@Override
public void finished() {
resetDone.postValue(true);
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
Job myJob = dispatcher.newJobBuilder()
.setService(SyncJobs.class)
.setReplaceCurrent(true)
.setTrigger(Trigger.executionWindow(0, 1))
.setTag(SyncJobs.SINGLE_ROUTE_SYNC)
.build();
dispatcher.mustSchedule(myJob);
}
@Override
public void allRoutes(List<RouteData> routeDataList) {
}
}).execute(context);
}
示例12: setup
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入依赖的package包/类
private static void setup(@NonNull final Context context, final int timeInSeconds) {
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
Job myJob = dispatcher.newJobBuilder()
// the JobService that will be called
.setService(DailyReminderService.class)
// uniquely identifies the job
.setTag(DailyReminderService.TAG)
// one-off job
.setRecurring(false)
// persist past a device reboot (requires boot receiver permission)
.setLifetime(Lifetime.FOREVER)
// start between 0 and 60 seconds from now
.setTrigger(Trigger.executionWindow(timeInSeconds, timeInSeconds + 30))
// overwrite an existing job with the same tag
.setReplaceCurrent(true)
// retry with exponential backoff
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
//.setExtras(myExtrasBundle)
.build();
dispatcher.mustSchedule(myJob);
}
示例13: queuePostCore
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入依赖的package包/类
public void queuePostCore(@NonNull FirebaseJobDispatcher dispatcher, @NonNull PostRequest postRequest) {
Bundle extras = new Bundle(2);
extras.putString(GenericJobService.JOB_TYPE, GenericJobService.POST);
extras.putParcelable(GenericJobService.PAYLOAD, postRequest);
dispatcher.mustSchedule(dispatcher.newJobBuilder()
.setService(GenericJobService.class)
.setTag(GenericJobService.POST)
.setRecurring(false)
.setLifetime(Lifetime.UNTIL_NEXT_BOOT)
.setTrigger(Trigger.executionWindow(0, 60))
.setReplaceCurrent(false)
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
.setConstraints(Constraint.ON_ANY_NETWORK, Constraint.DEVICE_CHARGING)
.setExtras(extras)
.build());
Log.d("FBJD", postRequest.getMethod() + " request is queued successfully!");
}
示例14: queueFileIOCore
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入依赖的package包/类
public void queueFileIOCore(@NonNull FirebaseJobDispatcher dispatcher, boolean isDownload,
@NonNull FileIORequest fileIORequest) {
Bundle extras = new Bundle(2);
extras.putString(GenericJobService.JOB_TYPE, isDownload ?
GenericJobService.DOWNLOAD_FILE : GenericJobService.UPLOAD_FILE);
extras.putParcelable(GenericJobService.PAYLOAD, fileIORequest);
dispatcher.mustSchedule(dispatcher.newJobBuilder()
.setService(GenericJobService.class)
.setTag(isDownload ? GenericJobService.DOWNLOAD_FILE : GenericJobService.UPLOAD_FILE)
.setRecurring(false)
.setLifetime(Lifetime.FOREVER)
.setReplaceCurrent(false)
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
.setConstraints(fileIORequest.onWifi() ? Constraint.ON_UNMETERED_NETWORK : Constraint.ON_ANY_NETWORK,
fileIORequest.isWhileCharging() ? Constraint.DEVICE_CHARGING : 0)
.setExtras(extras)
.build());
Log.d("FBJD", String.format("%s file request is queued successfully!", isDownload ?
"Download" : "Upload"));
}
示例15: schedulePeriodic
import com.firebase.jobdispatcher.FirebaseJobDispatcher; //导入依赖的package包/类
public static void schedulePeriodic(Context context, String tag, int period) {
Timber.d("Scheduling a periodic sync every " + period + " seconds");
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
Job myJob = dispatcher.newJobBuilder()
.setService(QuoteJobService.class)
.setTag(tag)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(period, period))
.setLifetime(Lifetime.UNTIL_NEXT_BOOT)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
.setReplaceCurrent(true)
.build();
dispatcher.mustSchedule(myJob);
}