use of com.firebase.jobdispatcher.FirebaseJobDispatcher in project FastHub by k0shk0sh.
the class NotificationSchedulerJobTask method scheduleJob.
public static void scheduleJob(@NonNull Context context, int duration, boolean cancel) {
if (AppHelper.isGoogleAvailable(context)) {
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
dispatcher.cancel(SINGLE_JOB_ID);
if (cancel)
dispatcher.cancel(JOB_ID);
if (duration == -1) {
dispatcher.cancel(JOB_ID);
return;
}
duration = duration <= 0 ? THIRTY_MINUTES : duration;
Job.Builder builder = dispatcher.newJobBuilder().setTag(JOB_ID).setRetryStrategy(RetryStrategy.DEFAULT_LINEAR).setLifetime(Lifetime.FOREVER).setRecurring(true).setConstraints(Constraint.ON_ANY_NETWORK).setTrigger(Trigger.executionWindow(duration / 2, duration)).setService(NotificationSchedulerJobTask.class);
dispatcher.mustSchedule(builder.build());
}
}
use of com.firebase.jobdispatcher.FirebaseJobDispatcher in project FastHub by k0shk0sh.
the class NotificationSchedulerJobTask method scheduleOneTimeJob.
public static void scheduleOneTimeJob(@NonNull Context context) {
if (AppHelper.isGoogleAvailable(context)) {
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
Job.Builder builder = dispatcher.newJobBuilder().setTag(SINGLE_JOB_ID).setReplaceCurrent(true).setRecurring(false).setTrigger(Trigger.executionWindow(30, 60)).setConstraints(Constraint.ON_ANY_NETWORK).setService(NotificationSchedulerJobTask.class);
dispatcher.mustSchedule(builder.build());
}
}
use of com.firebase.jobdispatcher.FirebaseJobDispatcher in project Passenger_Security by ujjwalagr.
the class JobClass method startJob.
public static void startJob(Context context) {
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
Job job = dispatcher.newJobBuilder().setLifetime(Lifetime.FOREVER).setService(SmsJobSchedule.class).setTag("SMS_SENT_MESSAGE_TAG").setReplaceCurrent(false).setRecurring(true).setTrigger(Trigger.executionWindow(0, 60)).setRetryStrategy(RetryStrategy.DEFAULT_LINEAR).build();
dispatcher.mustSchedule(job);
}
use of com.firebase.jobdispatcher.FirebaseJobDispatcher in project Passenger_Security by ujjwalagr.
the class JobClass method stopJob.
public static void stopJob(Context context) {
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
// Cancel all the jobs for this package
dispatcher.cancelAll();
// Cancel the job for this tag
dispatcher.cancel("SMS_SENT_MESSAGE_TAG");
}
use of com.firebase.jobdispatcher.FirebaseJobDispatcher in project anitrend-app by AniTrend.
the class JobSchedulerUtil method scheduleJob.
/**
* Schedules a new job service or replaces the existing job if one
* exists.
* @param context any valid application context
*/
public static void scheduleJob(Context context) {
ApplicationPref applicationPref = new ApplicationPref(context);
if (applicationPref.isAuthenticated() && applicationPref.isNotificationEnabled()) {
try {
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
Job syncJob = dispatcher.newJobBuilder().setService(JobDispatcherService.class).setTag(JOB_DISPATCHER).setRecurring(true).setLifetime(Lifetime.UNTIL_NEXT_BOOT).setTrigger(Trigger.executionWindow(MINIMUM_SYNC_TIME, applicationPref.getSyncTime())).setReplaceCurrent(true).setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL).setConstraints(Constraint.ON_ANY_NETWORK).build();
dispatcher.mustSchedule(syncJob);
Log.d("JobSchedulerUtil", "JobDispatcher has been scheduled from context: " + context);
} catch (FirebaseJobDispatcher.ScheduleFailedException ex) {
Log.d("JobSchedulerUtil", ex.getLocalizedMessage());
ex.printStackTrace();
}
} else
cancelJob(context);
}
Aggregations