Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid WifiManager - to HEX or not to HEX
    text
    copied!<p>I'm attempting to connect to wifi using Android programatically however when I input my WEP key in Hex - Logcat states it's too long. When I attempt to use plaintext - it states it is too short (and never connects). When I type it in manually outside the app I've built (by simply typing the password: superman) it connects! </p> <p>P.S.</p> <p>I'm attempting to use the following StackOverflow example:</p> <p><a href="https://stackoverflow.com/questions/8818290/how-to-connect-to-a-specific-wifi-network-in-android-programmatically">How do I connect to a specific Wi-Fi network in Android programmatically?</a></p> <p>With Hex:</p> <pre><code> String networkSSID = "ANDRE-PC_NETWORK"; String networkPass = "73:75:70:65:72:6d:61:6e"; </code></pre> <p>LOGCAT:</p> <pre><code>04-04 12:12:13.643: E/wpa_supplicant(594): Line 0: Too long WEP key 0 '"73:75:70:65:72:6d:61:6e"'. 04-04 12:12:13.643: E/WifiConfigStore(479): failed to set wep_key0: "73:75:70:65:72:6d:61:6e" 04-04 12:12:13.793: I/ActivityManager(479): Displayed com.nfc.linked/.Connect: +855ms 04-04 12:12:16.283: W/GAV2(3422): Thread[Service Reconnect,5,main]: Connection to service failed 1 </code></pre> <p>Without Hex: </p> <pre><code> String networkSSID = "ANDRE-PC_NETWORK"; String networkPass = "superman"; </code></pre> <p>LOGCAT:</p> <pre><code>04-04 12:23:10.913: E/wpa_supplicant(594): Line 0: Invalid WEP key length 8 - this network block will be ignored </code></pre> <p>SOURCE: </p> <pre><code>import java.util.List; import android.app.Activity; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.os.Bundle; import android.util.Log; import android.content.Context; public class Connect extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.connect); String networkSSID = "ANDRE-PC_NETWORK"; String networkPass = "superman"; WifiConfiguration conf = new WifiConfiguration(); conf.SSID = "\"" + networkSSID + "\""; //ssid must be in quotes conf.wepKeys[0] = "\"" + networkPass + "\""; conf.wepTxKeyIndex = 0; conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); conf.preSharedKey = "\""+ networkPass +"\""; conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); WifiManager wifiManager = (WifiManager)getSystemService(WIFI_SERVICE); wifiManager.addNetwork(conf); List&lt;WifiConfiguration&gt; list = wifiManager.getConfiguredNetworks(); for( WifiConfiguration i : list ) { if(i.SSID != null &amp;&amp; i.SSID.equals("\"" + networkSSID + "\"")) { wifiManager.disconnect(); wifiManager.enableNetwork(i.networkId, true); wifiManager.reconnect(); break; } } }} </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