Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // if gps is enabled and network location is disabled
- // note, GPS can be slow to obtain location data but is more accurate
- if (locationProviders.contains("gps") && !locationProviders.contains("network")) {
- // build a new alert dialog to inform the user that they only have GPS location services
- new AlertDialog.Builder(this)
- //set the message to display to the user
- .setMessage("Only GPS Enabled")
- // add the 'positive button' to the dialog and give it a
- // click listener
- .setPositiveButton("Enable Location Services",
- new DialogInterface.OnClickListener() {
- // setup what to do when clicked
- public void onClick(DialogInterface dialog,
- int id) {
- // start the settings menu on the correct
- // screen for the user
- startActivity(new Intent(
- Settings.ACTION_LOCATION_SOURCE_SETTINGS));
- }
- // add the 'negative button' to the dialog and
- // give it a click listener
- })
- .setNegativeButton("Close",
- new DialogInterface.OnClickListener() {
- // setup what to do when clicked
- public void onClick(DialogInterface dialog,
- int id) {
- // remove the dialog
- dialog.cancel();
- }
- // finish creating the dialog and show to the
- // user
- }).create().show();
- // if gps is disabled and network location services are enabled
- // network services are quick and fairly accurate, we are happy to use them
- } else if (!locationProviders.contains("gps") && locationProviders.contains("network")) {
- // do nothing at present...
- // if gps is disabled and network location services are disabled
- // the user has no location services and must enable something
- } else if (!locationProviders.contains("gps") && !locationProviders.contains("network")) {
- // build a new alert dialog to inform the user that they have no
- // location services enabled
- new AlertDialog.Builder(this)
- //set the message to display to the user
- .setMessage("No Location Services Enabled")
- // add the 'positive button' to the dialog and give it a
- // click listener
- .setPositiveButton("Enable Location Services",
- new DialogInterface.OnClickListener() {
- // setup what to do when clicked
- public void onClick(DialogInterface dialog,
- int id) {
- // start the settings menu on the correct
- // screen for the user
- startActivity(new Intent(
- Settings.ACTION_LOCATION_SOURCE_SETTINGS));
- }
- // add the 'negative button' to the dialog and
- // give it a click listener
- })
- .setNegativeButton("Close",
- new DialogInterface.OnClickListener() {
- // setup what to do when clicked
- public void onClick(DialogInterface dialog,
- int id) {
- // remove the dialog
- dialog.cancel();
- }
- // finish creating the dialog and show to the
- // user
- }).create().show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement