Cómo conectar Android a ningún SSID público y sin contraseña requerida

i can't connect Android on SSID established, i try WifiConfiguration but unsucessfull, my ssid is open (without password).

In Android UI i can connect, but on code i can't.

Alguien me ayude?

Tankyou.

EDIT:

mi código:

String networkSSID = "DL63.0.0.0.1";
        String networkPass = "";

        WifiConfiguration conf = new WifiConfiguration();
        conf.SSID = "\"" + networkSSID + "\"";
//        conf.wepKeys[0] = "\"" + networkPass + "\"";
//        conf.wepTxKeyIndex = 0;
        conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
//        conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);

        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("\"" + networkSSID + "\"")) {
                wifiManager.disconnect();
                wifiManager.enableNetwork(i.networkId, true);
                wifiManager.reconnect();

                Toast.makeText(this, "SSID: "+wifiManager.getConnectionInfo().getSSID(), Toast.LENGTH_SHORT).show();
                break;
            }
        }

        status.setText("SSID: "+wifiManager.getConnectionInfo().getSSID());

preguntado el 30 de enero de 12 a las 19:01

please show your code... what exactly have you tried ? -

I try this two codes (Answer 2 and 3): stackoverflow.com/questions/8818290/… -

what happens exactly ? any exceptions/error messages ? -

No errors, only return null on SSID ever. -

1 Respuestas

Probablemente porque wifiManager.reconnect(); starts an asynchronous process to connect. When your code reaches the last line, there is yet no connection (that takes time, may even be a minute or so), so null is the correct answer at that moment. You will need a listener to react on the connect event. See that question for details: https://stackoverflow.com/a/5890553/1503237

contestado el 23 de mayo de 17 a las 15:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.