Create an AlertDialog if there is no network connection to inform the user and request them.
Use this code as an example ...
protected void createNetErrorDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("You need a network connection to use this application. Please turn on mobile network or Wi-Fi in Settings.") .setTitle("Unable to connect") .setCancelable(false) .setPositiveButton("Settings", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent i = new Intent(Settings.ACTION_WIRELESS_SETTINGS); startActivity(i); } } ) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MyActivity.this.finish(); } } ); AlertDialog alert = builder.create(); alert.show(); }
Creating an Intent using Settings.ACTION_WIRELESS_SETTINGS as an action will launch an inline action for network settings.
source share