我正在创建一个 Firebase 作业调度程序,用于向服务器发送错误崩溃报告。我的服务不是从调度程序的 mustSchedule 方法开始的。这可能是因为我正在开始我的工作,而不是任何活动。这是我的代码...
启动服务代码:
public void scheduleJobForUploadCrashReport(Context context, Bundle serviceBundle) {
Logs.i(TAG, "scheduleJobForUploadCrashReport");
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
try {
Job job = createJobForuploadCrashReport(dispatcher, serviceBundle);
dispatcher.mustSchedule(job);
Logs.i(TAG, "dispatcher is scheduled---->");
} catch (FirebaseJobDispatcher.ScheduleFailedException e) {
Logs.e(TAG, "FirebaseJobDispatcher.ScheduleFailedException : " + e.getMessage());
e.printStackTrace();
}
}
创建工作的代码:
public Job createJobForuploadCrashReport(FirebaseJobDispatcher dispatcher, Bundle serviceBundle) {
Logs.i(TAG, "createJobForuploadCrashReport");
Job job = dispatcher.newJobBuilder()
.setLifetime(Lifetime.FOREVER)
.setService(UploadApkCrashReportService.class)
.setTag(mAppName + mModuleName)
.setReplaceCurrent(false)
.setRecurring(false)
.setTrigger(Trigger.executionWindow(0, 30))
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setExtras(serviceBundle)
.build();
return job;
}
提前致谢。