Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5934031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:03:24+00:00 2026-05-22T15:03:24+00:00

Plain and simple. I start an Activity and check if the phone has the

  • 0

Plain and simple. I start an Activity and check if the phone has the GPS module enabled or not. If it isn’t enabled, I prompt the user with a dialog and ask if he wants to manually enable it. On Yes I activate the Settings for Location. Now the user can enable it if he wants to, but I need to check what he has done.

try {
    isGPSEnabled = locationManager
            .isProviderEnabled(LocationManager.GPS_PROVIDER);
} catch (Exception ex) {}
if (isGPSEnabled) {
    locationManager.requestLocationUpdates(
            LocationManager.GPS_PROVIDER, 0, 0, locationListenerGps);
} else {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(
            "Your GPS module is disabled. Would you like to enable it ?")
            .setCancelable(false)
            .setPositiveButton("Yes",
                    new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog,
                                int id) {
                            // Sent user to GPS settings screen
                            final ComponentName toLaunch = new ComponentName(
                                    "com.android.settings",
                                    "com.android.settings.SecuritySettings");
                            final Intent intent = new Intent(
                                    Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                            intent.addCategory(Intent.CATEGORY_LAUNCHER);
                            intent.setComponent(toLaunch);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivityForResult(intent, 1);
                            dialog.dismiss();
                        }
                    })
            .setNegativeButton("No",
                    new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog,
                                int id) {
                            dialog.cancel();
                        }
                    });
    AlertDialog alert = builder.create();
    alert.show();
}

I need to know what the user has chosen in Location settings, when he comes back in order to proceed with my logic in code. Basically I need to wait for the user to make a choice and return to my activity, and also to recheck the status of gps module again.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:03:25+00:00Added an answer on May 22, 2026 at 3:03 pm

    Why not just check LocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) in your onActivityResult() method? When the user returns, this method should be called because you called startActivityForResult(). If the user has enabled GPS then isProviderEnabled() should now return a different result.

    Alternatively, always do the GPS check in your onResume method. If the user returns from the Location settings and hasn’t enabled GPS, then they will simply receive the same prompt until GPS is enabled.

    Or am I missing something?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Plain and simple issue: I would like to annotate my method parameter with some
Situation is simple: I post a plain HTML form with a textarea. Then, in
In my open-source plain C code I use this simple structure to read and
I need to upload a potentially huge plain-text file to a very simple wsgi-app
I have a simple three table reference. It looks plain enough. The associations there
Things are simple: press an icon and send the phone to standby. The frustrating
I am creating an app that has a suggestion box. When the user inputs
My question sounds the same as this but it isn't: Start a process in
I plan on building a simple, yet high usage webapp and need to settle
Plain-vanilla NHibernate setup, eg, no fluent NHibernate, no HQL, nothing except domain objects and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.