Possible Duplicate:
How to connect to a specific wifi network in android programmatically?
I know there are several questions like this one but I already tried everything I found in stackoverflow and other sites but nothing has solved my problem.
I am creating an access point from one device and I am trying to connect to it from another device programatically. The WifiConfiguration is exactly the same on both devices. I am able to find the network, but it won't connect to it! I am pretty sure that the AP is not the problem, because I am able to connect to it through the default Android wifi settings (entering the password by hand, etc..).
//when the network is found through startScan(), I try to connect:
WifiConfiguration wc=new WifiConfiguration();
wc.SSID="\"my_ssid\"";
wc.preSharedKey = "\"my_password\"";
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);
wc.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
int netId=wifi.addNetwork(wc);
wifi.enableNetwork(netId, true);
The addNetwork() is returning a valid network Id. I don't get any error. It just doesn't connect.
I already tried to change the WifiConfiguration to OPEN, and several other things but nothing works. The wifi is enabled too. I would be very grateful if somebody could help me with this.