You need to forget about the configured Wi-Fi network programmatically in Android 6.0

I implemented a system for programmatically connecting to Wi-Fi networks from my application, now I want to forget about the Wi-Fi networks settings programmatically from the application.

I have already implemented this in my application, and it works great on Android 5.0 and lower devices (less API 22).

For Android 6.0 and higher, the device does not work (higher and equal to API 23).

Please use the following code:

    val wifiManager = this@SelectWifiSettingsActivity.baseContext!!.getSystemService(android.content.Context.WIFI_SERVICE) as WifiManager
    val list = wifiManager.configuredNetworks
    for (i in list) {
        wifiManager.disableNetwork(i.networkId)
        wifiManager.saveConfiguration()
    }    

I also referred to the following link: stack overflow

There are also some changes in WIFI configurations in Android 6.0.

Please help me if anyone has a solution for this on Android 6.0 and above.

+5
source share
1 answer

-, saveConfiguration().

API 26.

- addNetwork (WifiConfiguration), updateNetwork (WifiConfiguration) removeNetwork (int) .

-, , , removeNetwork().

:

val wifiManager = this@SelectWifiSettingsActivity.baseContext!!.getSystemService(android.content.Context.WIFI_SERVICE) as WifiManager
    val list = wifiManager.configuredNetworks
    for (i in list) {
        wifiManager.removeNetwork(i.networkId)
    }  

... API Android M WifiManager .

WifiConfiguration, . WifiConfiguration, .

. Android M

+2

Source: https://habr.com/ru/post/1693902/


All Articles