-
-
Save Volcanoscar/c9080a3f4dae54515e2183ee08b28171 to your computer and use it in GitHub Desktop.
How to connect to a specific wifi network in Android programmatically?
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
WifiConfiguration wifiConfig = new WifiConfiguration(); | |
wifiConfig.SSID = String.format("\"%s\"", ssid); | |
wifiConfig.preSharedKey = String.format("\"%s\"", key); | |
WifiManager wifiManager = (WifiManager)getSystemService(WIFI_SERVICE); | |
//remember id | |
int netId = wifiManager.addNetwork(wifiConfig); | |
wifiManager.disconnect(); | |
wifiManager.enableNetwork(netId, true); | |
wifiManager.reconnect(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment