Android studio connect to wifi without password

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like