我正在使用 firebase 作业调度程序 api 在后台运行服务。在 Marshmallow 中它运行良好,但在使用 Oreo 设备时它无法运行。它显示错误或警告消息,例如
2019-02-04 14:20:22.285 2525-5699/? E/NetworkScheduler: Dropping task as app's play services SDK 版本不支持 Android O。请更新 SDK 或降低应用的目标 SDK 版本。包:com.webappclouds.jobserviceexample
我已经完成了 git hub 中的 firebase job dispatcher api step 中提到的内容。
MainActiviy.java
package com.webappclouds.jobserviceexample;
import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.content.ComponentName;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import com.firebase.jobdispatcher.Constraint;
import com.firebase.jobdispatcher.FirebaseJobDispatcher;
import com.firebase.jobdispatcher.GooglePlayDriver;
import com.firebase.jobdispatcher.Job;
import com.firebase.jobdispatcher.Lifetime;
import com.firebase.jobdispatcher.RetryStrategy;
import com.firebase.jobdispatcher.Trigger;
public class MainActivity extends AppCompatActivity {
String TAG="MAIN ACTIVITY";
FirebaseJobDispatcher dispatcher;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
}
public void startjob(View view) {
Log.d(TAG, "startjob: ");
Job job = createJob(dispatcher);
dispatcher.mustSchedule(job);
}
public void stopjob(View view) {
Log.d(TAG, "cancelJob: ");
dispatcher.cancelAll();
}
public Job createJob(FirebaseJobDispatcher dispatcher) {
Log.d(TAG, "createJob: ");
Job job = dispatcher.newJobBuilder()
// persist the task across boots
.setLifetime(Lifetime.FOREVER)
// Call this service when the criteria are met.
.setService(MakeService.class)
// unique id of the task
.setTag("LocationJob")
}
}
跃然一笑
犯罪嫌疑人X
相关分类