Skip to content

Android Networking Library listening for the Internet connectivity.

Notifications You must be signed in to change notification settings

mk7002/Android-Network-Connectivity

Repository files navigation

Android-Network-Connectivity

Android Networking Library listening for the Internet connectivity.

Getting Started

These instructions will help you set up this library easily on your current project and working in no time. You only need a few configurations to start working!

Installing

To be able to use the following library, you will need to add the following gradle dependency in your

build.gradle Project level

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

build.gradle module

implementation 'com.github.mk7002:Android-Network-Connectivity:Tag'

That is the basic set up needed to be able to use the library in your applications!

Usage

In your Activity

public class MainActivity extends AppCompatActivity {  
  
    Disposable disposable;  
  
  @Override  
  protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
		setContentView(R.layout.activity_main);  
		disposable = Network  
                .observeInternetConnectivity()  
                .subscribeOn(Schedulers.io())  
                .observeOn(AndroidSchedulers.mainThread())  
                .subscribe(connected -> {  
	                     
				  });  
  }  
  
    @Override  
  protected void onDestroy() {  
         super.onDestroy();  
		 if (disposable != null)  
            disposable.dispose();  
  }  
}

You can also customize the network settings

NetworkSettings settings=new NetworkSettings.Builder()  
        .setDEFAULT_HOST("www.google.com")  
        .setDEFAULT_TIMEOUT_IN_MILLIS(2500)  
        .setHttpResponse(1000)  
        .setInterval(1000)  
        .setInterval(1)  
        .build(); 
         
	disposable = Network  
        .observeInternetConnectivity(settings)  
        .subscribeOn(Schedulers.io())  
        .observeOn(AndroidSchedulers.mainThread())  
        .subscribe(connected -> {  
            
		  });

If you get any error relate to rxjava , then add RxJava library inside your build.gradle(module) file

 	implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
    	implementation 'io.reactivex.rxjava3:rxjava:3.0.0'

About

Android Networking Library listening for the Internet connectivity.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages