I am writing a program that should connect the phone to a WiFi point.
Next to the phone is a Dlink network router - without a password.
Did this guide https://stackoverflow.com/questions/8818290/how-to-connect-to-a-specific-wifi-network-in-android-programmatically
The phone connects to the network.
Made it possible to enter your network name via EditText - this does not work.
In the debugger, it works completely, however wifiManager.disconnect (); wifiManager.enableNetwork (i.networkId, true); wifiManager.reconnect (); - does these actions, but does not connect to the network.
public class MainActivity extends FragmentActivity { public EditText nameNetworkText; public EditText passwordText; public EditText typeNetworkText; String networkSSID = "DSL-2640U"; String networkPass = "12341234"; String nameNetwork; String password; String typeNetwork; public static final String TAG = "Basic Network Demo"; // Whether there is a Wi-Fi connection. private static boolean wifiConnected = false; // Whether there is a mobile connection. private static boolean mobileConnected = false; // Reference to the fragment showing events, so we can clear it with a button // as necessary. private LogFragment mLogFragment; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.network); nameNetworkText = (EditText) findViewById(R.id.nameNetwork); passwordText = (EditText) findViewById(R.id.password); } public void getAccess (View view) { nameNetworkText = (EditText) findViewById(R.id.nameNetwork); nameNetwork = nameNetworkText.getText().toString(); passwordText = (EditText) findViewById(R.id.password); password = passwordText.getText().toString(); typeNetworkText = (EditText) findViewById(R.id.networkType); typeNetwork = typeNetworkText.getText().toString(); String open = "open"; String wep = "wep"; String wpa = "wpa"; WifiConfiguration conf = new WifiConfiguration(); // WifiConfiguration conf1 = new WifiConfiguration(); conf.SSID = "\"" + nameNetwork + "\""; // conf1.SSID = "\"" + networkSSID + "\""; // conf.preSharedKey = "\""+ networkPass +"\""; if (typeNetwork.equals(open)) { conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); } if (typeNetwork.equals(wep)) { conf.wepKeys[0] = "\"" + password + "\""; conf.wepTxKeyIndex = 0; conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); } if (typeNetwork.equals(wpa)) { conf.preSharedKey = "\""+ password +"\""; } WifiManager wifiManager = (WifiManager)this.getSystemService(Context.WIFI_SERVICE); wifiManager.addNetwork(conf); List<WifiConfiguration> list = wifiManager.getConfiguredNetworks(); for( WifiConfiguration i : list ) { if(i.SSID != null && i.SSID.equals("\"" + nameNetwork + "\"")) { wifiManager.disconnect(); wifiManager.enableNetwork(i.networkId, true); wifiManager.reconnect(); break; } } } }
if(i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {? - Vladyslav Matviienko