I am trying to connect to a WiFi network from my Android app. I display the available WiFi networks in a ListView
.
If I click on the network name, it displays a dialog box and connects to WiFi. Once the user has logged into the network, it should display a popup with the network details instead of prompting for a password again.
How can I do this?
TextView textView = (TextView)view.findViewById(R.id.apName);
textView.setText(accessPoints.get(i);
textView.setPadding(60,0,0,0);
textView.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
final Dialog dialog =new Dialog(getActivity());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
Window window = dialog.getWindow();
dialog.setContentView(R.layout.password_dialog);
final Button connect = (Button)dialog.findViewById(R.id.connect);
Button cancel = (Button)dialog.findViewById(R.id.cancel);
connect.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
list<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
for( WifiConfiguration i : list ) {
if(i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
wifiManager.disconnect();
wifiManager.enableNetwork(i.networkId, true);
wifiManager.reconnect();
break;
}
}
}