Skip to content

Babar-Bashir/Android-Check-Internet-Connection

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Checking for Internet Connection

This is a background service that constantly checks if connection is available. You can select the URL to ping and the interval of this action.

How to

In your activity, where you want to start this service:

        Intent intent = new Intent(this, ConnectionService.class);
        // Interval in seconds
        intent.putExtra(ConnectionService.TAG_INTERVAL, 100);
        // URL to ping
        intent.putExtra(ConnectionService.TAG_URL_PING, "http://www.google.com");
        // Name of the class that is calling this service
        intent.putExtra(ConnectionService.TAG_ACTIVITY_NAME, this.getClass().getName());
        // Starts the service
        startService(intent);

Implement ConnectionService.ConnectionServiceCallback on your activity and override the methods:

    @Override
    public void hasInternetConnection() {
       // has internet
    }

    @Override
    public void hasNoInternetConnection() {
       // no internet :(
    }

Stop the service

 	stopService(new Intent(this, ConnectionService.class));

About

Service that checks periodically if internet connection is available.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%