我使用 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());
它的工作很好,它可以按时发送工作服务中定义的通知
现在我如何将其转换为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);
但我只在计划时发送一次通知,之后就不发送
我最好的猜测是你应该将setTrigger((更改为:
.setTrigger(Trigger.executionWindow(duration * 60, duration * 60))
已编辑以修复执行窗口