Archive

Posts Tagged ‘wifi’

Android: programmatically toggle wifi on/off

April 15th, 2009

To toggle wifi within your application, you will first need the following permissions:
android.permission.ACCESS_WIFI_STATE
android.permission.CHANGE_WIFI_STATE
android.permission.WAKE_LOCK

Then in your code, you need to get an WifiMananger:

wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);

To toggle wifi on/off:

if (wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(false);
} else {
wifiManager.setWifiEnabled(true);
}

That’s it ^_^! It’s really simple!
You can download the sample project here

Android Shogun Android, Mobile ,