I am writing an android app which will connect to a specific WPA access point, when connected, it will issue a http call. It will not save the network config. I have read al
I just had this very same problem. Seemingly everything was okay, but then - it wasn't.
What I found is this:
Android WifiStateMachine will not allow you to add or modify networks unless supplicant is running and connected-to. This affects services running on start-up and services running even if WIFI is off.
Android WifiConfigStore tracks owners of the wifi network by UID. It means that you may not be able to modify network created by another process.
The proper way to add a network is:
WifiManager.setWifiEnabled(true).WifiManager.pingSupplicant() returns true. WifiConfiguration, then pass it to WifiManager.addNetwork(). Make sure the value returned is not (-1).addNetwork() as an argument to WifiConfiguration.enableNetwork() call (unless it's -1). Note, that the boolean parameter means disableOthers and should be false, unless you have right to modify all other networks: it may fail internally, if you set it to true.This should allow you to add (and connect) programmatically to a new Wifi network.