DEV Community

Ashish S Patil
Ashish S Patil

Posted on

Internet bandwidth And Connectivity Check Library For Android

ConnectivityCheck is an Android library that allows you to figure out the quality of the current user's internet connection.
The library notifies you when the user's connection quality time to time.

https://github.com/Ashusnu/ConnectivityCheck

How to use:

Step 1) Add it in your root build.gradle at the end of repositories:

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

Enter fullscreen mode Exit fullscreen mode

Step 2) Add the dependency

implementation 'com.github.Ashusnu:ConnectivityCheck:$version'

Enter fullscreen mode Exit fullscreen mode

Step 3) Attach connectivity check listener in onCreate() block.

ConnectivityCheck.checkConnectionState(new ConnectivityCheck.connectionStateListener() {
            @Override
            public void connectionState(ConnectionInfo connectionInfo) {
            // do something with connectionInfo
            }

            @Override
            public void onError(Exception e) {
                // handle exceptions
            }
        }, this);

Enter fullscreen mode Exit fullscreen mode

Step 3) Finally start and stop connection check

To start connection check call startCheck() inside onResume() block

@Override
    protected void onResume() {
        super.onResume();
        ConnectivityCheck.startCheck();
    }

Enter fullscreen mode Exit fullscreen mode

To stop connection check call stopCheck()inside onPause() block

@Override
    protected void onPause() {
        super.onPause();
        ConnectivityCheck.stopCheck();
    }

Enter fullscreen mode Exit fullscreen mode

That's it

Top comments (0)