Reputation: 41
I have used broadcast receiver to check network connection, but with android 7.0 it's not allowed any more. So, I want to handle this problem with Job Scheduling, but I do not know how to do it. Is there any good resource about Job Scheduling or piece of code that check network status with Job Scheduling.
Upvotes: 0
Views: 582
Reputation: 10269
Frameworks, like Android JobScheduler or Firebase Jobdispatcher provide a feature that allow you to define constraints when a job should be executed. One constraint might be that network has to be available.
There are some implementations for Job scheduling on Android, like Android Jobscheduler or Firebase Jobdispatcher. This gives you an overview
If you use Firebase Jobdispatcher, you can define that you Job should only be executed if network is available, like this:
Job myJob = dispatcher.newJobBuilder()
// the JobService that will be called
.setService(MyJobService.class)
// uniquely identifies the job
.setTag("my-unique-tag")
// constraints that need to be satisfied for the job to run
.setConstraints(
// only run if any network is available
Constraint.ON_ANY_NETWORK
)
.build();
dispatcher.mustSchedule(myJob);
Source: Firebase Jobdispatcher
Upvotes: 1