public final class RxNetwork
extends java.lang.Object
Instances of RxNetwork can be created simply like this:
RxNetwork rxnetwork = RxNetwork.init(this));
// or event like this, if working only with internet strategies
RxNetwork rxnetwork = RxNetwork.init();
You can also configure various aspects of RxNetwork by using provided builder.
For example,
RxNetwork rxnetwork = RxNetwork.builder()
.defaultScheduler(AndroidSchedulers.mainThread())
.networkObservingStrategy(new YourCustomNetworkObservingStrategy())
.internetObservingStrategy(new YourCustomInternetObservingStrategy())
.build();
For more "dynamic" approach custom factories can be provided
RxNetwork rxnetwork = RxNetwork.builder()
.networkObservingFactory(new YourCustomNetworkObservingFactory())
.internetObservingFactory(new YourCustomInternetObservingFactory())
.build();
}
From Lollipop and up (API 21+) you can specify defaultNetworkRequest to be used
by built in network observing strategy:
NetworkRequest customRequest = new NetworkRequest.Builder()
.addCapability(NET_CAPABILITY_INTERNET)
.addTransportType(TRANSPORT_WIFI)
.build();
RxNetwork.builder().defaultNetworkRequest(customRequest).build();
| Modifier and Type | Class and Description |
|---|---|
static class |
RxNetwork.Builder
Build a new
RxNetwork. |
| Modifier and Type | Method and Description |
|---|---|
static RxNetwork.Builder |
builder() |
static RxNetwork |
init()
Create default implementation of RxNetwork if not using network observing strategies.
|
static RxNetwork |
init(android.content.Context context)
Create default implementation of RxNetwork.
|
io.reactivex.Observable<RxNetworkInfo> |
observe()
RxNetworkInfo connectivity observable with all the original
NetworkInfo information. |
io.reactivex.Observable<RxNetworkInfo> |
observe(NetworkObservingStrategy strategy)
RxNetworkInfo connectivity observable with all the original
NetworkInfo information
that uses custom defined strategy. |
io.reactivex.Observable<java.lang.Boolean> |
observeInternetAccess()
Real internet access observable.
|
io.reactivex.Observable<java.lang.Boolean> |
observeInternetAccess(InternetObservingStrategy strategy)
Real internet access observable with custom defined
strategy. |
io.reactivex.Observable<java.lang.Boolean> |
observeSimple()
Simple network connectivity observable based on observe()
that filters all the unnecessary information from
NetworkInfo and shows only
bare connection status changes. |
@NonNull public static RxNetwork init(@NonNull android.content.Context context)
@NonNull public static RxNetwork init()
@NonNull public static RxNetwork.Builder builder()
@NonNull public io.reactivex.Observable<RxNetworkInfo> observe()
NetworkInfo information.
Use this if you're interested in more than just the connection and could use more information of actual network information being emitted.
RxNetworkInfo containing network information@NonNull public io.reactivex.Observable<RxNetworkInfo> observe(@NonNull NetworkObservingStrategy strategy)
NetworkInfo information
that uses custom defined strategy.strategy - custom NetworkObservingStrategy instanceRxNetworkInfo containing network information@NonNull public io.reactivex.Observable<java.lang.Boolean> observeSimple()
NetworkInfo and shows only
bare connection status changes.
Use this if you don't care about all the NetworkInfo details.
Boolean ( true if network available and
connected, false if not )@NonNull public io.reactivex.Observable<java.lang.Boolean> observeInternetAccess()
Boolean ( true if there is real internet access,
false if not )@NonNull
public io.reactivex.Observable<java.lang.Boolean> observeInternetAccess(@NonNull
InternetObservingStrategy strategy)
strategy.strategy - custom InternetObservingStrategy instanceBoolean ( true if there is real internet access,
false if not )