Reputation: 569
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?
Upvotes: 5
Views: 1766
Reputation: 518
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
Upvotes: 2
Reputation: 14618
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.
Upvotes: 1