忘记网络在 Android Marshmallow 中不工作了?

Forgot network not working in Android Marshmallow?

我正在使用以下代码删除或忘记配置 Wi-Fi 网络:

WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifiManager.removeNetwork(networkID);

但它在 os 6.0 中不起作用,请推荐?

你应该这样使用:

WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
       int networkId = wifiManager.getConnectionInfo().getNetworkId();
       wifiManager.removeNetwork(networkId);
       wifiManager.saveConfiguration();      

希望对您有所帮助!!