Broadcast Intent when network state has changend
Asked Answered
S

3

16

Does Android broadcast an intent when the network state has changend, i.e. from GSM to Wifi? And if so what permission do I need and what is the intent action called?

Squiggle answered 20/4, 2010 at 14:43 Comment(0)
F
19

Update: please use this instead: https://mcmap.net/q/11687/-broadcast-intent-when-network-state-has-changend

Fraze answered 20/4, 2010 at 15:5 Comment(2)
I'm not familiar with the subject matter, but a talk at Defcon pointed out an error in this answer. See slide 51 from the presentation. Could somebody update this accordingly?Recondition
I don't see how this answer relates to the question. The network connectivity could change from cellphone network to Bluetooth tethering and the code would never know it. Please don't use this. AI's answer regarding ConnectivityManager.CONNECTIVITY_ACTION points in the right direction.Pastiness
A
10

There isn't anything exactly like what you are describing but you can use ConnectivityManager.CONNECTIVITY_ACTION to monitor changes and use the extras that come with it to see if the connection has changed from GSM to Wifi and vice versa. For this you need the permission android.permission.ACCESS_NETWORK_STATE and android.permission.ACCESS_WIFI_STATE for checking wifi information.

Angeliaangelic answered 20/4, 2010 at 18:6 Comment(1)
I don't see why CONNECTIVITY_ACTION isn't what was asked for. Also, personally, I don't need android.permission.ACCESS_WIFI_STATE to receive the CONNECTIVITY_ACTION event. Apart from that... thank you for providing the right answer to the question!Pastiness
B
1

Android will broadcast WifiManager.NETWORK_STATE_CHANGED_ACTION when the devices gains or looses wifi connectivity. You'll need the permission android.permission.ACCESS_WIFI_STATE to receive the intent. However, I'm not sure if there's something similar for GSM -> WIFI.

Briar answered 20/4, 2010 at 15:0 Comment(1)
In the question, WiFi was only mentioned as an example. The question refers to the network state in general, independently of the particular WiFi connectivity.Pastiness

© 2022 - 2024 — McMap. All rights reserved.