Is it possible to toggle WiFi radio (On/Off) programmatically on android phones?
Asked
Active
Viewed 1,564 times
3 Answers
7
Have a look at the WifiManager: http://developer.android.com/reference/android/net/wifi/WifiManager.html
Specifically:
boolean setWifiEnabled(boolean enabled)
Enable or disable Wi-Fi.

aioobe
- 413,195
- 112
- 811
- 826
2
To Enable WiFi:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(true);
Note: To access with WiFi state, we have to add following permissions inside the AndroidManifest.xml file:
android.permission.ACCESS_WIFI_STATE
android.permission.UPDATE_DEVICE_STATS
android.permission.CHANGE_WIFI_STATE

Valeh Ağayev
- 556
- 4
- 12
0
To actually toggle, meaning, switching the state, use:
WifiManager wm = ((WifiManager) activity.getSystemService(Context.WIFI_SERVICE));
wm.setWifiEnabled(!wm.isWifiEnabled());
and add the permissions:
android.permission.ACCESS_WIFI_STATE
android.permission.UPDATE_DEVICE_STATS
android.permission.CHANGE_WIFI_STATE

Oded Breiner
- 28,523
- 10
- 105
- 71