Hello all,
I googled it by days and got no success, I'm trying to connect to my
WPA/WPA2 network when I put the Wifi On, it all over codes...
If I was already connected to the network before I set the wifi off on the
program, when I set the wifi on it connect, but I want to enter with the
name of the network and the password...
The code that I got error is this:
wifiManager.setWifiEnabled(true);
Toast.makeText(context, "Off to On", Toast.LENGTH_LONG).show();
WifiManager wifi = (WifiManager)
getSystemService(Context.WIFI_SERVICE);
WifiConfiguration wc = new WifiConfiguration();
wc.SSID = "\"My Network\"";
wc.preSharedKey = "\"password\"";
wc.hiddenSSID = false;
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);
int res = wifi.addNetwork(wc);
Toast.makeText(context, "add Network returned " + res,
Toast.LENGTH_LONG).show();
boolean b = wifi.enableNetwork(res, true);
Toast.makeText(context, "enableNetwork returned " + b,
Toast.LENGTH_LONG).show();
wifiManager.setWifiEnabled(true);
I got -1 in the add Network and false in enableNetwork...
Someone know why?
Thanks in advance!
Endy
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en