title: How and what to set to Android WifiConfiguration.preSharedKey to connect to the WPA2 PSK WiFi network
body: <p>In Android 1.5 (also on 1.6)</p>
  
  <p>How to add an Access Point from code?</p>
  
  <p>Given Access point that supports WPA2.
  Here is my code snippet.</p>
  
  <pre><code>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 );
  </code></pre>
  
  <p>This code fails as in LogCat appear </p>
  
  <blockquote>
    <p>01-26 16:44:13.550: ERROR/wpa_supplicant(2032): Line 0: Invalid PSK 'password'.</p>
  </blockquote>
  
  <p>I am sure that this is the password and that all of the rest of the parameters are right.
  What do I do I miss?</p>