I'm creating an application for Android that connects to a wireless network with it's configuration passed. I followed this How to programmatically create and read WEP/EAP WiFi configurations in Android?, to connect to a WEP network, but it doesn't work. When I connect by the Wifi Settings it connects without any problem. Analyzing the WifiConfiguration from the the programmatically added network and from the added by the Wifi Settings the difference is their ip assigment and proxy settings:
# ProgrammaticallyAdded #
ID: 8 SSID: "quickframe" BSSID: null PRIO: 40
KeyMgmt: NONE Protocols: WPA RSN
AuthAlgorithms: OPEN SHARED
PairwiseCiphers: TKIP CCMP
GroupCiphers: WEP40 WEP104 TKIP CCMP
PSK:
eap:
phase2:
identity:
anonymous_identity:
password:
client_cert:
private_key:
ca_cert:
IP assignment: UNASSIGNED
Proxy settings: UNASSIGNED
LinkAddresses: [] Routes: [] DnsAddresses: []
# Added by Wifi Settings #
ID: 8 SSID: "quickframe" BSSID: null PRIO: 17
KeyMgmt: NONE Protocols: WPA RSN
AuthAlgorithms: OPEN SHARED
PairwiseCiphers: TKIP CCMP
GroupCiphers: WEP40 WEP104 TKIP CCMP
PSK:
eap:
phase2:
identity:
anonymous_identity:
password:
client_cert:
private_key:
ca_cert:
IP assignment: DHCP
Proxy settings: NONE
LinkAddresses: [192.168.0.89/24,] Routes: [0.0.0.0/0 -> 192.168.0.1,] DnsAddresses: [143.106.2.5,143.106.2.2,]
I also tried to add the IP assignment and Proxy settings by reflection. But it didn't work neither.
ID: 8 SSID: "quickframe" BSSID: null PRIO: 0
KeyMgmt: NONE Protocols: WPA RSN
AuthAlgorithms: OPEN SHARED
PairwiseCiphers: TKIP CCMP
GroupCiphers: WEP40 WEP104 TKIP CCMP
PSK:
eap:
phase2:
identity:
anonymous_identity:
password:
client_cert:
private_key:
ca_cert:
IP assignment: DHCP
Proxy settings: NONE
LinkAddresses: [] Routes: [] DnsAddresses: []
Anyone knows how to get thee IP and Proxy settings? I believe that these data will make the connection possible.
Thanks!
Actually the problem was in my WEP key, I was setting it like it was shown in the link I mentioned(How to programmatically create and read WEP/EAP WiFi configurations in Android?).
wc.wepKeys[0] = "\"" + password + "\"";
When I removed the quotation marks it worked.
wc.wepKeys[0] = "" + password + "";
So you only need to use quotation marks when setting the SSID.
wc.SSID = "\"" + ssid + "\"";
Hope it helps.
Regards.