bentzy
bentzy

Reputation: 1244

JobService NETWORK_TYPE_NOT_ROAMING not working in Android 8 Oreo API 26 Emulator

Our app does background work using a Job Service if the user is not roaming. This is how we schedule the job:

JobInfo.Builder jobInfoBuilder = new JobInfo.Builder(JobServicesIds.CONNECTIVITY.getValue(), new ComponentName(context.getPackageName(), ConnectivityJobService.class.getName()));
jobInfoBuilder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_NOT_ROAMING);
jobInfoBuilder.setPersisted(false);
JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
int result = jobScheduler.schedule(jobInfoBuilder.build());

To test this we use an emulator, roaming enabled, wifi not connected, set the data status to Roaming and start the app. To trigger the job we change the data status to Searching then Roaming. In Android Emulator API 24 the Job will trigger and everything is great. In Android Emulator API 26 the job will not trigger :(

Any Ideas? :)

Upvotes: 0

Views: 869

Answers (1)

krishank Tripathi
krishank Tripathi

Reputation: 626

Calling setRequiredNetworkType defines network as a strict requirement for your job. If the network requested is not available your job will never run. See setOverrideDeadline(long) to change this behavior. Calling this method will override any requirements previously defined by setRequiredNetwork(NetworkRequest); you typically only want to call one of these methods.

When your job executes in onStartJob(JobParameters), be sure to use the specific network returned by getNetwork(), otherwise you'll use the default network which may not meet this constraint.

for more details go to this source of the above answer https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#setRequiredNetwork(android.net.NetworkRequest)

Upvotes: 1

Related Questions