ReactiveNetwork: Connectivity return incorrect results ?
OS: Android 7.0 Emulator: Nexus S - Nougat API 24
When I turn off wifi on my phone, I return the result: connectivity.isAvailable() == true
It happens when turn on/off Wifi on phone several times.
ReactiveNetwork.observeNetworkConnectivity(this)
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.newThread())
.subscribe(new Consumer<Connectivity>() {
@Override public void accept(final Connectivity connectivity) {
EventBus.getDefault().post(new NetworkEvent(connectivity.isAvailable()));
}
});
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (8 by maintainers)
I’ve analyzed your code once again. Please note, you’re using NetworkInfo#isAvailable() method. According to the documentation it “Indicates whether network connectivity is possible”. Connectivity is possible, so the value is
true
. It’s correct behavior. If you want to check if you’re connected to the network or not, please use NetworkInfo#getState() method. In ReactiveNetwork, you can access it viaConnectivity#getState()
method. You can view available states in NetworkInfo.State documentation. E.g. it can beCONNECTED
,DISCONNECTED
,IDLE
and so on.Im sorry for reopening this issue but i have a question that is similar to it. Please check the code below and i struggle with it because of the incorrect value it returns. Because i do have internet connection and the library return false multiple times.