I'm implementing a code that verifies if there is an internet connection. If not, it starts the settings of the WiFi so the user can choose an Internet Connection.
The problem is that i want that when the user choose the connection and click back button, my activity verifies again if there is any connection to continue the execution, but it goes again to the NETWORK_INACTIVE
dialog.
Here is the code where i start the new activity:
protected boolean hasNetworkConnection() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
NetworkInfo mobile = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
try{
if (!wifi.isConnected()){
if(mobile==null || (mobile!=null && !mobile.isConnected())){
onCreateDialog(NETWORK_INACTIVE).show();
return false;
}
}
}catch(Exception e){
Log.e("AEP41-Has Network", ""+e.getStackTrace());
}
return true;
}
@Override
protected Dialog onCreateDialog(int id) {
AlertDialog.Builder builter = new AlertDialog.Builder(
AEP41Activity.this);
switch (id) {
case NETWORK_INACTIVE:
builter.setCancelable(false);
builter.setTitle("Erreur de Reseau");
builter.setMessage("Aucune connexion internet trouve");
builter.setNegativeButton("Sortir",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
AEP41Activity.this.finish();
}
});
builter.setNeutralButton("Choisir Connexion",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
startActivity(new Intent(
Settings.ACTION_WIFI_SETTINGS));
});
break;
default:
break;
}
return builter.create();
}
I've seen the option startActivityForResult(Intent, int)
but i did't found any solution with the use of the Settings.
Is there any way of doing this?
Thanks in advance ;)