Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

@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.

Is any setting required for Job Schedular to make it work on that device?

like image 983
Imran Khan Saifi Avatar asked Oct 18 '22 20:10

Imran Khan Saifi


1 Answers

It seems that Xiaomi MIUI operative system don't allow JobScheduler to run https://web.archive.org/web/20171001070316/http://c.mi.com/thread-8779-1-1.html

like image 153
david Avatar answered Oct 24 '22 23:10

david