0

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.

QHu91_IT
  • 189
  • 2
  • 12

1 Answers1

0

That is because WifiManager is deprecated.

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

Dharman
  • 30,962
  • 25
  • 85
  • 135
Fede
  • 321
  • 1
  • 9
  • Thanks, I try new method, it's can connect successful but no internet connection, don't know why :( https://stackoverflow.com/q/63469721/2749735 – QHu91_IT Aug 18 '20 at 13:31
  • If my answer worked you should mark it as best answer by clicking on the check on the left. If Android tells you that there is no internet connection it's probably a config issue for your router, not something related with the app. – Fede Aug 18 '20 at 13:35
  • If I connect manually by go to android system setting then it's normal but when I connect using code it's say no internet connection, I think config for router is fine. – QHu91_IT Aug 18 '20 at 13:38
  • `If my answer worked you should mark it as best answer `. No. As tomorrow there can still come better answers. Moreover one does not ask for points for oneself. – blackapps Aug 18 '20 at 16:07
  • Can't he just change it? :/ (if better answers appear) – Fede Aug 18 '20 at 20:14
  • Moreover @blackapps from the help centre: `Accepting an answer is not meant to be a definitive and final statement indicating that the question has now been answered perfectly. It simply means that the author received an answer that worked for them personally.`. I'm not asking for reputation, instead telling some people who might not know what the best answer is, how to actually use it. – Fede Aug 18 '20 at 20:25