Skip to content Skip to sidebar Skip to footer

Turn Off Wifi In Android Q

Is there any way besides the standard ConnectivityManager-API to modify wifi state in android q? I've just read google removed the api in android 10. Im willing to give the app and

Solution 1:

Your app must be a device owner as a variant to use wifiManager.setWifiEnabled(false) method that is deprecated started from Q.

Deprecation Exemptions: Device Owner (DO), Profile Owner (PO) and system apps. WifiManager

Solution 2:

You can use the following code to disable wifi :

try {
            WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
            return wifiManager.setWifiEnabled(false);
        } catch (Exception ex) {
            ex.printStackTrace();
            returnfalse;
        }

to disconnect wifi :

WifiManagerwifiManager= (WifiManager)context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
 wifiManager.disconnect();

and the following code to forget a particular wifi network :

try {
            WifiManagerwifiManager= (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
            ListwifiNetworks= wifiManager.getConfiguredNetworks();
            for (Object wifiConf : wifiNetworks) {
                if (((WifiConfiguration) wifiConf).SSID.equalsIgnoreCase(SSID)) {
                    return wifiManager.removeNetwork(wifiManager.getConnectionInfo().getNetworkId()) && wifiManager.saveConfiguration();
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

Post a Comment for "Turn Off Wifi In Android Q"