All Projects → keiferstone → Nonet

keiferstone / Nonet

Licence: apache-2.0
An Android library for monitoring network connectivity

Programming Languages

java
68154 projects - #9 most used programming language

NoNet

Maven Central Javadoc Build Status Android Arsenal

NoNet is an Android library for monitoring network connectivity.

Sample Usage

Monitor for network connectivity events and show a snackbar when disconnected:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    NoNet.monitor(this)
            .poll()
            .snackbar();
}

Set the global configuration:

NoNet.configure()
        .endpoint("https://google.com")
        .timeout(5)
        .connectedPollFrequency(60)
        .disconnectedPollFrequency(1);

Make a one-off network connectivity check with a custom configuration, showing a toast if disconnected, and provide a callback to be invoked on result:

NoNet.check(this)
        .configure(configuration)
        .toast()
        .callback(new Monitor.Callback() {
            @Override
            public void onConnectionChanged(int connectionStatus) {
                // TODO
            }
        })
        .start();

RxJava Support

Create an Observable from a Monitor that emits connectivity events:

NoNet.monitor(this)
        .banner()
        .observe()
        .subscribe(connectionStatus -> {...});

Note: Calling Monitor.observe() without declaring the io.reactivex.rxjava2:rxjava dependency in your build.gradle will cause errors at compile-time.

ProGuard

If you're using ProGuard, you may need to add these lines to your proguard-rules.pro:

-dontwarn io.reactivex.**
-dontwarn okio.**

Download

Download the latest AAR or grab via Gradle:

compile 'com.keiferstone:nonet:2.0.4'

or Maven:

<dependency>
  <groupId>com.keiferstone</groupId>
  <artifactId>nonet</artifactId>
  <version>2.0.4</version>
</dependency>

License

Copyright 2017 Keifer Stone

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].