- We drive into Google
android turn off wifi programmatically
Follow the first link to en-SO
We get the answer:
The following permissions are required in the manifest:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
To enable / disable Wi-Fi, you can use this code (in the activation class):
WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(true); wifiManager.setWifiEnabled(false);
And this is where you can check whether it is enabled or not:
boolean wifiEnabled = wifiManager.isWifiEnabled()