I have an app that is programmatically connecting to an IOT device's OPEN network. The IOT network is not "active" and Android seems to want to connect back to an active SSID. By turning the pictured options off, (wifi advanced settings) the phone keeps from jumping networks. I do not want my users to have to do this.
Is there a way to force the connection to my desired network? Or do I need to continually check the SSID, disconnect and reconnect?
Here is my current code. This works in most intsances of users staying connected but some phones running Android 8.0 seem to switch back to another network quickly.
val config = WifiConfiguration()
config.SSID = "\"${network.SSID}\""
config.hiddenSSID = true
config.priority = 0xBADBAD
config.status = WifiConfiguration.Status.ENABLED
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE)
(manager?.addNetwork(config))?.let { netID->
manager?.disconnect()
manager?.enableNetwork(netID, true)
manager?.reconnect()
}