I try connect to wifi and i can connect with password.But if wifi hasn't no password i can't connect,How can i?
this my code
public void connectWithoutPasswordToWifi(String networkSSID) { android.net.wifi.WifiConfiguration conf = new android.net.wifi.WifiConfiguration(); conf.SSID = "\"" + networkSSID + "\""; WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiManager.addNetwork(conf); List<android.net.wifi.WifiConfiguration> list = wifiManager.getConfiguredNetworks(); for (android.net.wifi.WifiConfiguration connect : list) { if (connect.SSID != null && connect.SSID.equals("\"" + networkSSID + "\"")) { wifiManager.disconnect(); wifiManager.enableNetwork(connect.networkId, true); wifiManager.reconnect(); break; } } } EDIT: I found this How connect Android to no SSID public and no Password requered
1 Answer
WifiConfiguration conf = new WifiConfiguration(); conf.SSID = "\"" + networkSSID + "\""; For Open network you need to do this:
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); 0