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?
Asked
Active
Viewed 1.7k times
3 Answers
19
Update: please use this instead: https://stackoverflow.com/a/2677519/241869
-
1I'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](http://www.eecs.berkeley.edu/~emc/slides/SevenWaysToHangYourselfWithGoogleAndroid.pdf). Could somebody update this accordingly? – jakar Aug 09 '11 at 20:11
-
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. – class stacker Dec 20 '12 at 15:08
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.

Al.
- 2,285
- 2
- 22
- 30
-
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! – class stacker Dec 20 '12 at 15:11
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.

Erich Douglass
- 51,744
- 11
- 75
- 60
-
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. – class stacker Dec 20 '12 at 15:13