3

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.

enter image description here

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()
        }
temp_
  • 1,238
  • 2
  • 12
  • 24
  • Possible duplicate (https://stackoverflow.com/questions/48749798/after-connecting-to-wifi-programmatically-disconnects-a-few-seconds-later/50062119#50062119) – Denis Loh Aug 01 '18 at 20:10

0 Answers0