I have got a list of configured Wifi Networks by wifiManager.getConfiguredNetworks() method. I displayed them in a Listview. Now whichever listItem I click , it connects to the same single Network only. I want to connect to the network that was clicked.
Here is my Java code
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String networkSSID = list.get(position).SSID;
String networkPass = list.get(position).preSharedKey;
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + networkSSID + "\"";
conf.preSharedKey = "\""+ networkPass +"\"";
int netId = wifiManager.addNetwork(conf);
wifiManager.disconnect();
wifiManager.enableNetwork(netId,true);
wifiManager.reconnect();
}
});
I use below block of code