Skip to content

An Open library for android to check for internet connections

Notifications You must be signed in to change notification settings

arashkhoeini/ConnectivityChecker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ConnectivityChecker

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...

Initializaion

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(R.id.button); 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(); } }); } }); ```

About

An Open library for android to check for internet connections

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages