简体   繁体   English

作业调度程序在小米 android 中不起作用

[英]job scheduler not working in xiaomi android

The Job Schedular set as follows作业计划设置如下

 ComponentName mServiceComponent = new ComponentName(context, TestJobService.class);
    JobInfo.Builder builder = new JobInfo.Builder(jobId, mServiceComponent);
    builder.setPeriodic(3 * 60 * 1000); 
    builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_NONE); 
    builder.setRequiresDeviceIdle(false); 
    builder.setRequiresCharging(false);
    builder.setPersisted(true);
    JobScheduler jobScheduler = (JobScheduler) ChaseForceApplication.getAppContext().getSystemService(Context.JOB_SCHEDULER_SERVICE);
    jobScheduler.schedule(builder.build());

The TestJobService class is like this: TestJobService 类是这样的:

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class TestJobService extends JobService {

@Override
public boolean onStartJob(JobParameters params) {
    Utility.writeToTheFile(ChaseForceApplication.getAppContext(), "\n\n Job Scheduler StartJob with jobid="+params.getJobId()+" set at " + new Date().toString());

    sendBroadcast(new Intent(this, OnSingleAlarmReceiver.class));
    return false;
}

@Override
public boolean onStopJob(JobParameters params) {
    Log.i(ChaseForceApplication.TAG, "on stop job: " + params.getJobId());
    Utility.writeToTheFile(this, "on stop job: " + new Date().toString());
    return false;
}

}

It's working on most devices, even in other xiaomi phones but in Xiaomi Redmi 3S it is not working.它适用于大多数设备,甚至适用于其他小米手机,但在小米红米 3S 中却无法使用。

Is any setting required for Job Schedular to make it work on that device? Job Schedular 是否需要任何设置才能使其在该设备上运行?

小米 MIUI 操作系统似乎不允许 JobScheduler 运行https://web.archive.org/web/20171001070316/http://c.mi.com/thread-8779-1-1.html

From your app settings/info page, try to enable auto start and then retry with job scheduler.从您的应用设置/信息页面,尝试启用自动启动,然后使用作业调度程序重试。 It will work.它会起作用。 You need to enable autostart for your app.您需要为您的应用启用自动启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM