I have following code, which has to connect to certain WiFi spot with WPA type:
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + sSSID + "\"";
if (wType == WifiType.WPA)
{
conf.preSharedKey = "\""+ sPass +"\"";
}
else if (wType == WifiType.WEP)
{
conf.wepKeys[0] = "\"" + sPass + "\"";
conf.wepTxKeyIndex = 0;
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
}
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
wifiManager.addNetwork(conf);
//
wifiManager.disconnect();
wifiManager.enableNetwork(conf.networkId, true);
wifiManager.setWifiEnabled(true);
if (wifiManager.reconnect())
{
Log.i(TAG, "successfully connected");
}
Things is I get in the log message, claiming that successfully connected
but nothing happens and connection is not obtained. I thought maybe this is just because it takes some time to obtain it and procedure finishes async, but even after waiting a while connection has not be obtained.
Would you tell me what am I doing wrong here? The Android documentation does not give a lot of details regarding WifiManager class.