Wie und was muss auf Android WifiConfiguration.preSharedKey eingestellt werden, um eine Verbindung zum WPA2 PSK WiFi-Netzwerk herzustellen?

In Android 1.5 (auch auf 1.6)

Wie füge ich einen Access Point aus dem Code hinzu?

Gegebener Access Point, der WPA2 unterstützt. Hier ist mein Code-Schnipsel.

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiConfiguration wc = new WifiConfiguration();
// This is must be quoted according to the documentation 
// http://developer.android.com/reference/android/net/wifi/WifiConfiguration.html#SSID
wc.SSID = "\"SSIDName\"";
wc.preSharedKey  = "password";
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 );

Dieser Code schlägt fehl, wie in LogCat angezeigt

01-26 16: 44: 13.550: ERROR / wpa_supplicant (2032): Zeile 0: Ungültiges PSK-Kennwort.

Ich bin sicher, dass dies das Passwort ist und dass alle anderen Parameter stimmen. Was vermisse ich?

Antworten auf die Frage(3)

Ihre Antwort auf die Frage