简体   繁体   English

Android-仍然无法以编程方式删除Wifi网络

[英]Android - Still can't remove Wifi Network Programatically

After reading several other questions/answers, I'm still having an issue using wifiManager.removeNetwork to work. 阅读其他几个问题/答案后,使用wifiManager.removeNetwork仍然无法正常工作。

According to: 根据:

Android - Cant Remove Wifi Network Programatically- The method removeNetwork(int) in the type WifiManager is not applicable for the arguments (String) Android-无法以编程方式删除Wifi网络-WifiManager类型的方法removeNetwork(int)不适用于参数(字符串)

and

How to forget a wireless network in android programmatically? 如何以编程方式忘记android中的无线网络?

...my code should work: ...我的代码应该可以工作:

WifiManager wifiMAN = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);

for (WifiConfiguration wifiCon : wifiMAN.getConfiguredNetworks()) {
    if (wifiCon.SSID.equals( "\""+ targetNetworkName +"\"")) {
        wifiMAN.removeNetwork(wifiCon.networkId)) {
        wifiMAN.saveConfiguration();
        break;
    }
}

However, when I test on API 23 it doesn't work. 但是,当我在API 23上进行测试时,它不起作用。 Looking through the code nothing appears depreciated and the code works on API 21. Anyone have any ideas? 仔细检查代码,似乎什么都不会贬值,并且代码可以在API 21上运行。任何人都有想法吗?

This is intended behavior. 这是预期的行为。 As of Android M apps are not allowed to modify networks that they did not create. 从Android版本开始,不允许M应用修改其未创建的网络。

See: https://code.google.com/p/android/issues/detail?id=187347 and https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-network 请参阅: https : //code.google.com/p/android/issues/detail?id=187347https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-网络

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android - 无法以编程方式删除Wifi网络 - WifiManager类型中的方法removeNetwork(int)不适用于参数(String) - Android - Cant Remove Wifi Network Programatically- The method removeNetwork(int) in the type WifiManager is not applicable for the arguments (String) 我可以以编程方式检测当前WiFi网络上是否有任何Chromecast设备? - Can i programatically detect if there are any Chromecast devices on the current WiFi network? 以编程方式断开连接后重新连接到WiFi网络 - Reconnecting to a WiFi Network after disconnecting from it Programatically SSID与BSSID:通过Android以编程方式连接到Wifi /使用WifiManager连接到网络 - SSID vs BSSID: Connecting to Wifi via Android Programatically / Using WifiManager to connect to a network Android中的WiFi网络编程 - WiFi network programming in android 我可以识别与wifi网络连接的所有android的主机名吗? - can I identify host name of all android connected with a wifi network? 为什么我不能在 Pixel 2 上设置 wifi 感知网络 - Why Can't i setup a wifi aware network on Pixel 2 我可以删除仍在运行的Java 6和Android吗? - Can I remove Java 6 and Android still working? 删除WIFI网络作为设备所有者 - Remove WIFI-Network as device owner Android:以编程方式删除特定的复选框 - Android: Programatically remove a specific checkbox
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM