0

I had tried this code but it was not working in the Android newest version.

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>

WifiManager wifiManager = (WifiManager)this.getApplicationContext().getSystemService(Context.WIFI_SERVICE); 
wifiManager.setWifiEnabled(true); // for enable
wifiManager.setWifiEnabled(false) // for disable 
Bruno Rohée
  • 3,436
  • 27
  • 32
Josort
  • 11
  • 2
  • Define not working. Does it throw an exception? DO nothing? Do something but not what you expected? Also please note this code won't connect to wifi, if it worked it would just enable it. – Gabe Sechan Aug 29 '22 at 04:05
  • I think so that Starting Android Q version has restricted this and developers can't disable/enable wifi and 4G programmatically. – Josort Aug 29 '22 at 04:19

0 Answers0