0

I am making a check if the user is connected to the internet. If the user is not connected then prompt the user to turn on data services.

This is the code that I am using to prompt the user to turn on data services if not connected

@Override
public void onClick(DialogInterface dialog, int which) {  
    startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
    dialog.dismiss();   
}

The above code works fine but it opens the wifi settings. Please how can I modify the code to open the image shown below

enter image description here

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Blaze
  • 2,269
  • 11
  • 40
  • 82
  • Possible duplicate of [How can I launch mobile network settings screen from my code](http://stackoverflow.com/questions/6000452/how-can-i-launch-mobile-network-settings-screen-from-my-code) – Iamat8 May 19 '16 at 10:19
  • @Mohit I have tried the options but did not work – Blaze May 19 '16 at 10:36

1 Answers1

1
public boolean isNetworkAvailable() {
    ConnectivityManager connectivity = (ConnectivityManager) ctx
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity == null) {
        return false;
    } else {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null) {
            for (int i = 0; i < info.length; i++) {
                if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }
            }
        }
    }
    return false;
}
Chetna
  • 154
  • 1
  • 1
  • 10