Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The reason for the my sorrow is here <a href="http://code.google.com/p/android/issues/detail?id=6272" rel="nofollow noreferrer">in this Documentation issue</a></p> <p>While <a href="http://developer.android.com/reference/android/net/wifi/WifiConfiguration.html#preSharedKey" rel="nofollow noreferrer">documentation here</a> states </p> <blockquote> <p>"Pre-shared key for use with WPA-PSK. When the value of this key is read, the actual key is not returned, just a "*" if the key has a value, or the null string otherwise."</p> </blockquote> <p>It is correct, but very important what it <strong>does not say</strong> is that expected here ether 64 byte hash result of the linux command </p> <pre><code>wpa_passphrase &lt;ssid&gt; [passphrase] </code></pre> <p>or Access Point's password <strong>IN DOUBLE QUOTES!</strong></p> <p>So in case that Access Point's PSK is <strong><em>"example"</em></strong> it has to be passed in java like this </p> <pre><code>WifiConfiguration myWiFiConfig = new WifiConfiguration(); ... myWiFiConfig.preSharedKey = "\"example\""; ... </code></pre> <p>OR </p> <pre><code>myWiFiConfig.preSharedKey = "0a0b0f62170ecc5bcf721b6ff170b8b560101b5d56b00a26abec217e0bb4aa1f"; </code></pre> <p>For all the rest of you that will stumble on this the right way is:</p> <p>Copy&amp;Paste it as is and save your self half a day of pain we already spent on it (Special Thanks to <a href="https://stackoverflow.com/users/27479/reflog">Reflog</a>)</p> <pre><code>WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiConfiguration wc = new WifiConfiguration(); 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>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload