Skip to content

DroidNet is an Android Networking Library listening for network connection state and Internet connectivity with the assumption that active internet connection or not. Connecting to a network doesn’t necessarily mean that device has active internet connection

License

Notifications You must be signed in to change notification settings

BlackBlind567/DroidNet

 
 

Repository files navigation

DroidNet Download Build Status FOSSA Status Hex.pm

DroidNet is an Android Networking Library listening for network connection state and Internet connectivity with assumption that active internet connection or not. Connecting to a network doesn’t necessarily mean that device has active internet connection

Spread Some ❤️

GitHub followers Twitter Follow

Getting Started

These instructions will help you set up this library easily on your current project and working in no time. You only need a few configurations to start working!

Installing

To be able to use the following library, you will need to add the following gradle dependency in your

build.gradle Project level

 repositories {
        jcenter()
    }

build.gradle module

implementation 'com.job:droidnet:2.0.0'

That is the basic set up needed to be able to use the library in your applications!

Permissions

First, we need to add these permission to our Android Manifest file :

<uses-permission android:name="android.permission.INTERNET" />

That's it, you have set up the required permissions and ready to go!

Usage

In your Main Application

import com.droidnet.DroidNet;
...


public class MyApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        DroidNet.init(this);
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        DroidNet.getInstance().removeAllInternetConnectivityChangeListeners();
    }
}

In your Activity

import com.droidnet.DroidListener;
import com.droidnet.DroidNet;
...


public class MainActivity extends AppCompatActivity implements DroidListener {

    //...

    private DroidNet mDroidNet;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //...
        mDroidNet = DroidNet.getInstance();
        mDroidNet.addInternetConnectivityListener(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mDroidNet.removeInternetConnectivityChangeListener(this);
    }

    @Override
    public void onInternetConnectivityChanged(boolean isConnected) {
      
        if (isConnected) {
            //do Stuff with internet
            netIsOn();
        } else {
            //no internet
            netIsOff();
        }
    }

    private void netIsOn(){...}

    private void netIsOff(){...}
}

Take a look at this sample project which has a sample implementation of the library.

Contributing and Issues

Please feel free to contribute or open issues, if any and I will be happy to help out!

Proguard

You are all set.

About

DroidNet is an Android Networking Library listening for network connection state and Internet connectivity with the assumption that active internet connection or not. Connecting to a network doesn’t necessarily mean that device has active internet connection

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%