Firebase Job Dispatcher无法在OREO设备上调度作业 [英] Firebase Job Dispatcher not Scheduling jobs on OREO devices

查看:109
本文介绍了Firebase Job Dispatcher无法在OREO设备上调度作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个firebase作业调度程序,该调度程序计划在网络发生变化时运行,该作业在棉花糖设备(23 API级别)上可以正常运行,但是运行时使用的相同代码不能在奥利奥设备上调度作业(26 API级别) )

I have a firebase job dispatcher which is scheduled to run whenever network changes ,the job is working perfectly on a marshmallow device (23 API level) but the same code when run is not scheduling jobs on a oreo device(26 API level)

这是我的工作服务代码:

Here is my Job Service code:

public class MyJobService extends JobService {


@Override
public boolean onStartJob(JobParameters job) {

    Log.d("Executing","Job");
    Realm realm = Realm.getDefaultInstance();

    RealmResults<JsontoSend> realmResults = realm.where(JsontoSend.class).findAll();
   if(!realmResults.isEmpty()) {
        for (JsontoSend jsontoSend : realmResults) {
            final Intent intent = new Intent(getApplicationContext(), PostUploadIntentService.class);
            intent.putExtra("object", jsontoSend.getJson());
            new Thread(new Runnable() {
                @Override
                public void run() {
                    startService(intent);
                }
            }).run();
        }
    }


    return true;
}

@Override
public boolean onStopJob(JobParameters job) {
        Log.d("instopjob","cancelled");
        return true;

    }
}

这是我创建作业的代码:

This is my code where i have created the job :

 synchronized  public static void schedule(@NonNull final Context context){
    if(sInitialized)
        return;

    Driver driver=new GooglePlayDriver(context);
    FirebaseJobDispatcher dispatcher=new FirebaseJobDispatcher(driver);

    Job myJob = dispatcher.newJobBuilder()
            .setService(MyJobService.class)
            .setTag(JOB_TAG)
            .setRecurring(true)
            .setTrigger(Trigger.executionWindow(5, 60))
            .setLifetime(Lifetime.FOREVER)
            .setConstraints(Constraint.ON_ANY_NETWORK)
            .setReplaceCurrent(false)
            .setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
            .build();

    dispatcher.schedule(myJob);
    sInitialized=true;

}

我想做的是如果我没有Internet连接,然后将数据存储在本地数据库中,然后每当我连接到Internet并与服务器同步数据时就运行一个作业.以上代码在棉花糖设备上运行良好但工作从未计划在oreo设备上进行.

What i am trying to do is if i do not have internet connection then storing the data in local database and then running a job whenever i connect to internet and sync the data with server .The above code is working perfectly on marshmallow device but the job is never scheduled on oreo devices.

推荐答案

这里的问题可能是因为您使用的GooglePlayDriver依赖于要在设备上显示的Google Play服务.如果服务不可用,则不会安排作业. 因此,如果您定位到高于5.0的设备(在大多数情况下是正确的),则必须使用android的

well the problem here is probably because you use GooglePlayDriver which relies on google play services to be presented on the devices. If the services are not available the job will not be scheduled. So if you target on devices higher than 5.0 (which is true in most cases) you have to use android's JobScheduler build in since lollipop.

这篇关于Firebase Job Dispatcher无法在OREO设备上调度作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆