Created
August 12, 2014 10:35
-
-
Save kenota/0f088ad9df78cbd3d1fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.