Reputation: 153
I am trying to connect to a wifi network programatically. Android connects to it, but after few seconds it drops the connection and automatically connects to the previous one.
If i try to connect through the settings, android connects to my desire network and stay connected.
Am I missing something?
The wifi network the I am trying to connect does not have internet access. It is a open network created by arduino + esp8266. I am trying to do something like the configuration method of chromecast.
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = "\"" + iotWifi + "\"";
wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
wifiConfiguration.priority = 40;
int res = wifiManager.addNetwork(wifiConfiguration);
wifiManager.saveConfiguration();
wifiManager.disconnect();
wifiManager.enableNetwork(res, true);
wifiManager.reconnect();
Upvotes: 1
Views: 370
Reputation: 328
with android lP version, android checks the network internet status and if connected network do not have internet and in previous connected network(any of) have internet ,Android device gives preference to internet enable network.
Upvotes: 2