Sritam Saha
Sritam Saha

Reputation: 69

Does BroadcastReceiver for android.net.conn.CONNECTIVITY_CHANGE actually check internet connectivity?

I have made use of a BroadcastReceiver for IntentFilter named android.net.conn.CONNECTIVITY_CHANGE but while checking through the emulator, I found out that even if there is no true connectivity to the internet, if the mobile data is switched on in the emulator it shows that the connection is alive.

CASE | MO_DATA | MO_WIFI | PC_INTER | RESP
---- | ------- | ------- | -------- | ----
1    | ON      | ON      | ON       | ON
2    | ON      | OFF     | ON       | ON
3    | OFF     | ON      | ON       | ON
4    | OFF     | OFF     | ON       | OFF
5    | ON      | ON      | OFF      | ON
6    | ON      | OFF     | OFF      | ON
7    | OFF     | ON      | OFF      | ON
8    | OFF     | OFF     | OFF      | OFF

The response shows ON even when there is no internet connectivity in the PC in cases 5, 6 and 7 above only because either of mobile data/wifi or both are switched ON and the actual status of non-availability of internet is not reflected.

Is there any way to solve this issue?

Upvotes: 0

Views: 324

Answers (2)

Ajay Shrestha
Ajay Shrestha

Reputation: 2455

BroadcastReceiver with intent filter android.net.conn.CONNECTIVITY_CHANGE gets fired when there is change in the network. Either Network Connected - Disconnected or Vice versa

Upvotes: 0

Deepesh
Deepesh

Reputation: 533

One way to check whether you have working internet connection is to make a request to Google.com and If you get the response 200 then you have a working net connection otherwise not.

If you will use CONNECTIVITY MANAGER then there is no way to find out if the connected network has working internet or not as sometime it happens like we are connected with WiFi but it doesn't work. Hope this will help you..

Upvotes: 2

Related Questions