Project Url: draxdave/netWatch
Introduction: Simple Android library to notify Android device network changes and react properly.
More: Author   ReportBugs   

Simple Android library to notify Android device network changes and react properly.

Preview GIF

netWatch - Simple Android library to notify Android device network changes and react properly


  • Detects internet connection changes(Connect / Disconnect)
  • Alerts user via a customizable status-bar notification message on connection loos / hides it on connection regain
  • Asks for a direct connection(Ping) to a reliable CDN(changeable IP address) to make sure user connected to internet
  • Checks connectivity periodically (duration calculated automatically)
  • Handles app close and open states
  • Changeable messages and drawables


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

allprojects {
        repositories {
            maven { url '' }

Step 2. Add the dependency

dependencies {
            implementation 'com.github.draxdave:netWatch:0.d.6'

Step 3. Register NetWatch

Add below code inside base activity or Application class

                .setCallBack(new NetworkChangeReceiver_navigator() {
                    public void onConnected(int source) {
                        // do some thing

                    public View onDisconnected() {
                        // do some other stuff

                        return null;//To display a dialog simply return a custom view or just null to ignore it

Available options

  • setIcon : Statusbar notification drawable graphic
  • setCallBack : onConnect and onDisconnect callbacks
  • setMessage : Statusbar notification message
  • setNotificationCancelable : Statusbar notification cancelable
  • setNotificationEnabled : Show statusbar notification on disconnect from internet
  • setNotificationBuilder : Create your own statusbar notification to show
  • unregister : disable NetWatch
  • isConnected : get latest internet connection status

  • And ...

Extra configs

Target server IP address

Add following line inside string.xml file :

<string name="netwatch_target_ping_server_ip_add"></string>

Disconnect message text

Add following line inside string.xml file :

<string name="netwatch_lost_connection">No internet connection</string>

Final speech

Feel free to engage! This tiny library have a lot to do obviously . So help it if you liked it. There is always better solutions and libraries so search more and you'll found a better code.
Correct my mistakes and rewrite them in case you found some thing better or a more convenient way to handle issues.

You can use any part of this small library as you wish .

About Me
GitHub: Trinea
Facebook: Dev Tools