Android does not detect data connection

I know that there are several topics in this thread, but they do not answer my question. I want to be able to detect when the device does not have a data connection. I tried checking the NetworkInfo route if its null, isConnected (), isAvailable (), etc. The problem is that they work fine (return false or null) when the Wi-Fi or mobile network is turned off, however, when they are turned on but there is no signal, they return true. Is there a way to detect a lack of data connection due to a lack of signal?

+4
source share
3 answers

create a repeater and catch the broadcast

Action for network events in android sdk

+1
source

You can try pinging google.com. If there is no answer, you can be sure that there is no connection (if the user is not in the country where he is blocked).

0
source

I am using ConnectivityManager.getActiveNetworkInfo.isConnectedOrConnecting ()

I just checked this 5 minutes ago to make sure, and if everything works, and I leave my home until my router is no longer within range and the network indicator in the status bar shows the network, the call to isConnectedOrConnecting () from application returns false.

I believe that is not the behavior that you see?

0
source

All Articles