I want to create app functionality to turn on WIFI programmatically. In android wifi.setWifiEnabled method was deprecated.
1 Answer
First, you need to ask the permission in the manifest file
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
Then in the activity file, you can disable wifi
WifiManager wifiManager = (WifiManager) this.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(true);
wifiManager.setWifiEnabled(false);
boolean wifiEnabled = wifiManager.isWifiEnabled()
1 Comment
Ninad Hire
not working prnt.sc/aN2ZU6Qm_peb