This is my code, The return value is always false. I have 'Location' permission enabled. i am using this code to programatically connect to a different network(OPEN)[code is not given here. I am using enableNetwork() and reconnect()]. But, then phone automatically connects back to the previous network. This issue is observed in google pixel, v8.1.0. I have checked in android v7. works fine.
WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
List<WifiConfiguration> configurations = wifiManager.getConfiguredNetworks();
for (WifiConfiguration config : configurations) {
Log.d("bhargav","SSID "+config.SSID);
//here it always returns false.
LibreLogger.d(this,"Disabling "+config.SSID+", result -> "+wifiManager.disableNetwork(config.networkId));
}