姬長信(Redy)

Android – Firebase jobdispatcher


我想知道是否可以使用Firebase jobdispatcher来安排网址命中并获取响应以更新数据库.
我希望它每天晚上运行一次.有谁知道这是否可能?

我找不到这样做的好例子.我已经阅读了android文档和https://github.com/firebase/firebase-jobdispatcher-android#user-content-firebase-jobdispatcher-.

我需要使用Firebase jobdispatcher,因为我的目标是API 16.

提前致谢.

UPDATE

这就是我每天安排一次的工作.

final int periodicity = (int) TimeUnit.HOURS.toSeconds(24);
final int toleranceInterval = (int) TimeUnit.HOURS.toSeconds(1);

FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
Job job = dispatcher.newJobBuilder()
        .setService(UpdateTVJobService.class)
        .setTag(JOB_TAG)
        .setTrigger(Trigger.executionWindow(periodicity, periodicity + toleranceInterval))
        .setLifetime(Lifetime.FOREVER)
        .setRecurring(true)
        .setReplaceCurrent(true)
        .build();

int result = dispatcher.schedule(job);

if (result != FirebaseJobDispatcher.SCHEDULE_RESULT_SUCCESS) {
    Log.d("JOB_TAG", "ERROR ON SCHEDULE");
}