Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to specified WiFi network in Android [duplicate]

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.

like image 949
Sebastian Breit Avatar asked Dec 05 '25 19:12

Sebastian Breit


1 Answers

After continuous try/fail tests, I got the solution. The SSID and password (presharedkey) have to be between quotes JUST ON THE CLIENT SIDE!. The SSID and password in the Wificonfiguration of the AP does not need quotes.

after changing this, it started to work.

Every day I am more disappointed of this kind of "wizard" solutions in Android....

like image 167
Sebastian Breit Avatar answered Dec 07 '25 09:12

Sebastian Breit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!