This is the same code as my other question link but this time I want to know how to connect to the Wi-Fi network and modify its parameters in the code there are two comments where they are concerned about questions
private final BroadcastReceiver wifiScanReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION))
{
wifiList = wifiManager.getScanResults();
WifiElements wifiElements = new WifiElements(LoginActivity.this, wifiList, R.layout.wifi_items);
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
builder.setTitle("Elija una red para establecer conexión");
View v = LayoutInflater.from(LoginActivity.this).inflate(R.layout.wifi_view_ssid, null);
builder.setView(v);
ListView netList = (ListView) v.findViewById(R.id.lv_ssid);
netList.setAdapter(wifiElements);
netList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
/**como decir que se conecte a esta wifi??? 1 duda*/
//despues de conectar satisfactoriamente muestra el dialogo para que entre user y passwd
showdialog(wifiList.get(i).SSID);
}
});
builder.create().show();
}
}
};
//******************** SHOW DIALOG *********************
public void showdialog(final String ssidWifi) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Nombre de usuario y contraseña");
builder.setMessage(ssidWifi);
builder.setCancelable(true);
View v = LayoutInflater.from(this).inflate(R.layout.login_show, null);
builder.setView(v);
final TextInputEditText textUser = (TextInputEditText) v.findViewById(R.id.user_name);
final TextInputEditText textPassw = (TextInputEditText) v.findViewById(R.id.user_passw);
builder.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if(textUser.getText().toString().isEmpty())
textUser.setError("@string/error_field_required");
else if(textPassw.getText().toString().isEmpty())
textPassw.setError("@string/error_field_required");
else
{
/**logica de la conexion, como establezco el proxy, user, passwd y el apartado omitir proxy para. 2 duda*/
}
}
});
builder.create().show();