GithubHelp home page GithubHelp logo

kiptechie / internetavailabilitychecker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aggarwalankit/internetavailabilitychecker

1.0 1.0 0.0 148 KB

this project checks if internet is present or not on device. Connecting to network doesn't mean internet access so this project pings google to check if internet is present or not

License: Apache License 2.0

Java 100.00%

internetavailabilitychecker's Introduction

InternetAvailabilityChecker

this project checks if active internet is present or not on device. Connecting to network doesn't mean internet access so this project pings google to check if internet is present or not

How To Use

To use the library follow the following steps:

  1. Add the dependency as follows:
    compile 'com.treebo:internetavailabilitychecker:$library_version'
    
  2. Initialise it in application’s onCreate() function. This is necessary step before starting using the library because it needs context to register connectivity broadcast receiver. It stores only weakreference to the context, so no need to worry about memory leaks. Also it does lazy registration of receiver; i.e. it registers receiver whenever first listener attaches to listen to internet changes and unregister itself when last listener stops listening.
    InternetAvailabilityChecker.init(this);
    
  3. Implement InternetConnectivityListener interface where ever you want to listen to internet connectivity changes (E.g. in activity, fragment or service).
    public class MainActivity extends AppCompatActivity implements InternetConnectivityListener {
        @Override
        public void onInternetConnectivityChanged(boolean isConnected) {
            //do something based on connectivity
        }
    }
    
  4. Get instance of InternetAvailabilityChecker and Add listener whenever you want to start listening to connectivity changes (e.g. in activity’s onCreate() function). It keeps a weakreference to the subscriber and clears the references whenever subscriber gets destroyed (when there is no more strong reference referencing it).
    mInternetAvailabilityChecker = InternetAvailabilityChecker.getInstance();
    mInternetAvailabilityChecker.addInternetConnectivityListener(this);
    
  5. Remove listener whenever you are done (e.g. in activity’s onDestroy(), fragment’s onDetach() or service’s onDestroy()).
    mInternetAvailabilityChecker.removeInternetConnectivityChangeListener(this);
    

internetavailabilitychecker's People

Contributors

ankitaggarwal1992 avatar aggarwalankit avatar

Stargazers

Timothy Serem avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.