Android usando wifimanager para conectarse a la red segura WPA-PSK
so he rastreado todos los hilos aquí y en cualquier otro lugar donde google me lleve. Pero aún tengo problemas para conectarme a las redes WPA PSK. Aquí está mi código, tengo 2 campos de edición de texto desde los cuales leo SSID y PSK y luego una casilla de verificación para seleccionar si SSID está oculto o no.
EditText mSSID = (EditText) findViewById(R.id.wifiTVssidcurrent);
String networkSSID = mSSID.getText().toString();
EditText mWPA = (EditText) findViewById(R.id.wifiTVwpacurrent);
String networkWPA = mWPA.getText().toString();
// Update text to show that connection is pending
TextView wifiStatus = (TextView) findViewById(R.id.wifiTVconnectionstatus);
wifiStatus.setText("Connecting to " + networkSSID);
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiConfiguration wc = new WifiConfiguration();
wc.SSID = "\"".concat(networkSSID).concat("\"");
wc.preSharedKey = "\"".concat(networkWPA).concat("\"");
CheckBox mSSIDHidden = (CheckBox) findViewById(R.id.wifiCBhiddenssid);
wc.hiddenSSID = false;
if (mSSIDHidden.isChecked()) {
wc.hiddenSSID = true;
}
wc.status = WifiConfiguration.Status.ENABLED;
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
int res = wifi.addNetwork(wc);
Log.d("WifiPreference", "add Network returned " + res );
boolean b = wifi.enableNetwork(res, true);
Log.d("WifiPreference", "enableNetwork returned " + b );
boolean c = wifi.reconnect();
Log.d("WifiPreference", "reconnect returned " + c );
Lo que veo en el teléfono después de ejecutar esto es que se crea un AP en la configuración, pero no se conecta. Y si intento usar el AP creado manualmente desde la configuración posterior, tampoco puedo conectarme. Pero si creo el AP desde dentro de la configuración, obtengo la conexión como debería.
En cuanto a poner SSID y WPA PSK, he intentado tanto "\" ". Concat (networkSSID) .concat (" \ ""); y "\" "+ networkSSID +" \ ""; con el mismo resultado.
Cualquier consejo será muy bienvenido. Saludos cordiales Lasse