14

I am about to build my own dialog to notifiy the user the app doesn't reach the internet, and I am planning to put two buttons on it. Settings, and Cancel as it is seen in many other apps.

I am wondering now, How do I launch settings directly on Wireless & networks page?

Pentium10
  • 204,586
  • 122
  • 423
  • 502

1 Answers1

31
/**
     * Display a dialog that user has no internet connection
     * @param ctx1
     *
     * Code from: http://osdir.com/ml/Android-Developers/2009-11/msg05044.html
     */
    public static void showNoConnectionDialog(Context ctx1) {
        final Context ctx = ctx1;
        AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
        builder.setCancelable(true);
        builder.setMessage(R.string.no_connection);
        builder.setTitle(R.string.no_connection_title);
        builder.setPositiveButton(R.string.settings, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                ctx.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
            }
        });
        builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                return;
            }
        });
        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                return;
            }
        });

        builder.show();
    }
Pentium10
  • 204,586
  • 122
  • 423
  • 502
  • 1
    this is really very much helpful, i had also implemented same as yours. But still can you please help me to sort it out: http://stackoverflow.com/questions/3889241/wireless-settings-dialog – Paresh Mayani Aug 30 '11 at 07:04