Search code examples
androidandroid-wifi

Android can not connect to wifi already connect before


Step1: Open android wifi system setting, connect to wifi A and leaver (not forget)

Step2: Open app and connect to wifi A, function wifiManager.addNetwork(wifiConfig) always return -1

If I forget wifi A and go to app connect then it will connect success.

If wifi A already connect before, in Android 8 and below wifiManager.getConfiguredNetworks() can return this wifi A so I can get networkId to enable this, but in Android 10 is not return anything, Android 9 not tested because I don't have.

I'm not Android developer so I just try my best, any idea? thanks.


Solution

  • That is because WifiManager is deprecated.

    From what I've understood you want to connect to a WiFi network, this is the new method.