Skip to content

Instantly share code, notes, and snippets.

@kenota
Created August 12, 2014 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenota/0f088ad9df78cbd3d1fd to your computer and use it in GitHub Desktop.
Save kenota/0f088ad9df78cbd3d1fd to your computer and use it in GitHub Desktop.
String networkSSID = "test";
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + networkSSID + "\"";
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
wifiManager.addNetwork(conf);
List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
for( WifiConfiguration i : list ) {
if(i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
wifiManager.disconnect();
wifiManager.enableNetwork(i.networkId, true);
wifiManager.reconnect();
break;
}
}
@NayaneshGupte
Copy link

Hi,
I referred your comment on
http://stackoverflow.com/questions/8818290/how-do-i-connect-to-a-specific-wi-fi-network-in-android-programmatically
This is not working. reconnect() returns true but it doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment