我使用 Jobschuler 每 x 分钟(动态确定)发送通知,如下所示
ComponentName componentName = new ComponentName(context,ClsJobService.class);
JobInfo.Builder builder = new JobInfo.Builder(0, componentName)
.setPeriodic(duration * 60 * 1000); //setting in millisecond
JobScheduler jobScheduler = (JobScheduler) context.getSystemService (Context.JOB_SCHEDULER_SERVICE);
jobScheduler.schedule(builder.build());
并且它工作得很好,它会按时发送通知 JobService 中定义
现在我怎么能把它转换成firebase作业调度程序,我确实喜欢这样
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
Job job = dispatcher.newJobBuilder()
.setService(ClsJobService.class)
.setTag("notification") // uniquely identifies the job
.setTrigger(Trigger.executionWindow(0, duration * 60))
.setLifetime(Lifetime.FOREVER)
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
.setRecurring(true)
.build();
dispatcher.mustSchedule(job);
但我只在安排时发送一次通知,之后就没有了