Hi,
Here i am going to write about “How do we Enable and Disable Wifi programmatically in android application?”
To Enable WiFi:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifi.setWifiEnabled(true);
To Disable WiFi:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifi.setWifiEnabled(false);
Note:
To access with WiFi state, we have to add following permissions inside the AndroidManifest.xml file:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission> <uses-permission android:name="android.permission.UPDATE_DEVICE_STATS"></uses-permission> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>