GithubHelp home page GithubHelp logo

jobgetabu / droidnet Goto Github PK

View Code? Open in Web Editor NEW
65.0 3.0 12.0 252 KB

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: Other

Java 49.46% Kotlin 50.54%
internet-connectivity network

droidnet's Introduction

DroidNet

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 {
        maven { url 'https://jitpack.io' }
    }

build.gradle module

implementation 'com.github.JobGetabu:DroidNet:v2.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.old.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.old.DroidListener;
import com.droidnet.old.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.

Stargazers over time

Stargazers over time

TODO

  • add kotlin support
  • use lifecycle aware components
  • livedata
  • android Q and latest permissions

droidnet's People

Contributors

jobgetabu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

droidnet's Issues

JCenter shutdown

JCenter repository is gonna shut down soon. For that reason can you change host of that library on some other, alternative repository?

Will the connectivity be checked whenever a network change is detected?

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

Will this function be run if I am in the middle of a process and the internet connection is lost? I want to display a dialog saying there is an issue with the internet.

Doesn't update on connection lost

While connected to wi-fi, if I pull out the internet cable from the router the listener doesn't detect that the internet connection is lost. It still returns true on isConnected.
Restarting the app makes the listener return the real state of the connectivity.

I've tested it on a "new-test-project" only to see how it works following the code you provided in ReadMe.

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.