Giter VIP home page Giter VIP logo

netwatch's Introduction

netWatch

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

Features:

  • 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

Installation

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

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

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

 NetWatch.builder(activity)
                .setIcon(R.drawable.ic_signal_wifi_off)
                .setCallBack(new NetworkChangeReceiver_navigator() {
                    @Override
                    public void onConnected(int source) {
                        // do some thing
                    }

                    @Override
                    public View onDisconnected() {
			            // do some other stuff
			            
			            
			            return null;//To display a dialog simply return a custom view or just null to ignore it
                    }
                })
                .setNotificationCancelable(false)
                .build();

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">8.8.8.8</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 .

netwatch's People

Contributors

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