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.S.
I'm attempting to use the following StackOverflow example:
How do I connect to a specific Wi-Fi network in Android programmatically?
With Hex:
String networkSSID = "ANDRE-PC_NETWORK";
String networkPass = "73:75:70:65:72:6d:61:6e";
LOGCAT:
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
Without Hex:
String networkSSID = "ANDRE-PC_NETWORK";
String networkPass = "superman";
LOGCAT:
04-04 12:23:10.913: E/wpa_supplicant(594): Line 0: Invalid WEP key length 8 - this network block will be ignored
SOURCE:
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<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
for( WifiConfiguration i : list ) {
if(i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
wifiManager.disconnect();
wifiManager.enableNetwork(i.networkId, true);
wifiManager.reconnect();
break;
}
}
}}
Try:
String networkPass = "73757065726d616e";