Faced a weird behaviour of NetworkInfo.isConnectedOrConnecting()
when it is called from Service
. It simply returns false
although phone is connected to the Network. From Activities and Fragments this snippet works as expected.
public boolean isOnline() {
if (mContext == null) {
return false;
}
NetworkInfo netInfo = mConnectivityManager.getActiveNetworkInfo();
return netInfo != null && netInfo.isConnectedOrConnecting();
}
Anyone faced this issue? Perhaps there's another method for checking network connection inside Services.