Skip to content

Detect CONNECTIVITY CHANGE in Android 7 and above whether app is in foreground or in background

Notifications You must be signed in to change notification settings

jitsm555/Android-Network-Connectivity

Repository files navigation

Android-Network-Connectivity

Detect CONNECTIVITY CHANGE in Android 7 and above whether app is in foreground or in background

Pre-requisites

  • Android SDK 27
  • Android Build Tools v27.0.2
  • Android Support Repository

Getting Started

This sample uses the Gradle build system. To build this project, use the "gradlew build" command or use "Import Project" in Android Studio.

Schedule job

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    private void scheduleJob() {
        JobInfo myJob = new JobInfo.Builder(0, new ComponentName(this, NetworkSchedulerService.class))
                .setRequiresCharging(true)
                .setMinimumLatency(1000) 
                .setOverrideDeadline(2000) // set the max delay for receiving call
                .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                .setPersisted(true)
                .build();

        JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
        jobScheduler.schedule(myJob);
    }

About

Detect CONNECTIVITY CHANGE in Android 7 and above whether app is in foreground or in background

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages