You should call isConnected
instead of isConnectedOrConnecting
if you want to determine whether the device is connected at the time of call to isOnline
.
Generally, there are many problems/bugs with hardware-features APIs on the emulator, this might be one of them. Your code is fine.