Hi i'm trying to connect my app to a specific access point using the wifimanager api. as it stands I have a list of all access point in my area,from this list i am storing them in a array and picking which one to connect to . but at this stage is dose not connect . can someone help me .
( this is a open network i'm trying to connect to . ) here is my code:
public void WifiConfiguration(){
try {
ScanResult networkData = getIntent().getParcelableExtra("networkData");
WifiManager wifiManager = (WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
String networkPassWord = "";
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + networkData.SSID + "\"";
conf.BSSID = "\"" + networkData.BSSID + "\"";
conf.hiddenSSID = true;
conf.wepKeys[0] = "\"" + networkPassWord + "\"";
conf.wepTxKeyIndex = 0;
conf.status = WifiConfiguration.Status.ENABLED;
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
conf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
conf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
conf.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
conf.preSharedKey = "\""+ networkPassWord +"\"";
//conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
Log.d(TAG, "Initialising WIFI Manager");
int id = wifiManager.addNetwork(conf);
Log.d(TAG, "conf.SSID: "+conf.SSID);
Log.d(TAG, "id: "+id);
wifiManager.disconnect();
wifiManager.enableNetwork(id, true);
wifiManager.reconnect();
Log.d(TAG, "Should be connected....");
} catch (Exception e) {
Log.d(TAG, e.toString());
}
}