An Open library for android to check for internet connections
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


An Open library for android to check for Internet connection.

If you do a lot of Internet Request in your Android application, and you need check for Internet connection every single time, You probably gonna need this library. This is a very simple library which checks for Internet connection and if the user was connected to Internet, It will do the network task. Else it will show an AlertDialog.

How to Use?

For using this library, you need to add this as module. To do so, first download it, then go to your project in android studio and select File >New >Import Module...


Right now there is only one class in this library, ConnectivityChecker. The class ConnectivityChecker has two constructor. The first one takes 2 arguments, and the second one takes 5 arguments. The first constructor builds AlertDialog with default texts for message, retry button, and setting button. But the second constructor has three more arguments and takes these texts from you.

Checking for connection

The class ConnectivityChecker has a main method which you are going to use when sending internet requests, doIfConnected(Doable task). This method takes one Doable object and check for Internet Connection. If user was connected, it performs the method doTask(). Else it will show the AlertDialog.

Other Methods

isDialogCancelable(Boolean cancelable) : Alert Dialog is cancelable by default. If you want to change this behaviour, you can use this method.

setDialogAlertMessage(String message) : You can change alertDialog message by using this method.

setCustomDialog(AlertDialog customDialog) : If you want to use a different AlertDialog, You can use this method.

Usage Example

``` Button b = (Button) findViewById(; b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ConnectivityChecker cc = new ConnectivityChecker(getApplicationContext(),MainActivity.this, "Oops! No internet" , "Retry" , "Setting"); cc.doIfConnected(new Doable() { @Override public void doTask() { Toast.makeText(getApplicationContext(),"Doing Task.... ",Toast.LENGTH_SHORT).show(); } }); } }); ```