the GPS can be toggled by exploiting a bug in the power manager widget. see this xda thread for discussion.

here's some example code i use

private void turnGPSOn(){
    String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

    if(!provider.contains("gps")){ //if gps is disabled
        final Intent poke = new Intent();
        poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider"); 
        poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
        poke.setData(Uri.parse("3")); 
        sendBroadcast(poke);
    }
}

private void turnGPSOff(){
    String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

    if(provider.contains("gps")){ //if gps is enabled
        final Intent poke = new Intent();
        poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
        poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
        poke.setData(Uri.parse("3")); 
        sendBroadcast(poke);
    }
}

use the following to test if the existing version of the power control widget is one which will allow you to toggle the gps.

private boolean canToggleGPS() {
    PackageManager pacman = getPackageManager();
    PackageInfo pacInfo = null;

    try {
        pacInfo = pacman.getPackageInfo("com.android.settings", PackageManager.GET_RECEIVERS);
    } catch (NameNotFoundException e) {
        return false; //package not found
    }

    if(pacInfo != null){
        for(ActivityInfo actInfo : pacInfo.receivers){
            //test if recevier is exported. if so, we can toggle GPS.
            if(actInfo.name.equals("com.android.settings.widget.SettingsAppWidgetProvider") && actInfo.exported){
                return true;
            }
        }
    }

    return false; //default
}
Answer from Ben H on Stack Overflow
🌐
Stagecoach
stagecoachbus.com › help-and-contact › faqs › how-do-i-enable-gps-on-my-android
How do I enable GPS on my Android? | Stagecoach
How do I enable GPS on my Android? Set up GPS on your Android in a few simple steps: Find and tap your 'Settings' menu · Find and tap 'Location' - your phone may show 'Location services' or 'Location access' instead ·
People also ask

What’s the difference between GPS and GPS on Android?
GPS refers to the satellite-based system. On Android, GPS is enhanced with extra data sources like Wi-Fi and mobile networks for better precision.
🌐
fieldpromax.com
fieldpromax.com › blog › how-to-turn-on-gps-in-2025
How to Turn On GPS in 2025: Easy Guides for Android & Tracking Tips
How do I use GPS on Android phone for offline maps?
Download the area you need in Google Maps while connected to Wi-Fi. GPS will still work without a signal as long as the map is saved.
🌐
fieldpromax.com
fieldpromax.com › blog › how-to-turn-on-gps-in-2025
How to Turn On GPS in 2025: Easy Guides for Android & Tracking Tips
What is GPS on an Android phone, and how does it work?
GPS uses satellites to determine your phone’s location. Android adds data from Wi-Fi and cell towers to make it more accurate.
🌐
fieldpromax.com
fieldpromax.com › blog › how-to-turn-on-gps-in-2025
How to Turn On GPS in 2025: Easy Guides for Android & Tracking Tips
🌐
Android Developers
developer.android.com › core areas › sensors and location › change location settings
Change location settings | Sensors and location | Android Developers
In order to use the location services ... location provider, connect your app using the Settings Client, then check the current location settings and prompt the user to enable the required settings if needed....
🌐
Google Support
support.google.com › accounts › answer › 3467281
Manage your Android device’s location settings - Google Account Help
Choose location mode (Android 4.4—8.1) Open your device's Settings app. Tap Security and Location Location. If you don't find "Security and Location," tap Location. ... High accuracy: Use GPS, Wi-Fi, mobile networks, and sensors to get the most accurate location.
Top answer
1 of 16
160

the GPS can be toggled by exploiting a bug in the power manager widget. see this xda thread for discussion.

here's some example code i use

private void turnGPSOn(){
    String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

    if(!provider.contains("gps")){ //if gps is disabled
        final Intent poke = new Intent();
        poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider"); 
        poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
        poke.setData(Uri.parse("3")); 
        sendBroadcast(poke);
    }
}

private void turnGPSOff(){
    String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

    if(provider.contains("gps")){ //if gps is enabled
        final Intent poke = new Intent();
        poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
        poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
        poke.setData(Uri.parse("3")); 
        sendBroadcast(poke);
    }
}

use the following to test if the existing version of the power control widget is one which will allow you to toggle the gps.

private boolean canToggleGPS() {
    PackageManager pacman = getPackageManager();
    PackageInfo pacInfo = null;

    try {
        pacInfo = pacman.getPackageInfo("com.android.settings", PackageManager.GET_RECEIVERS);
    } catch (NameNotFoundException e) {
        return false; //package not found
    }

    if(pacInfo != null){
        for(ActivityInfo actInfo : pacInfo.receivers){
            //test if recevier is exported. if so, we can toggle GPS.
            if(actInfo.name.equals("com.android.settings.widget.SettingsAppWidgetProvider") && actInfo.exported){
                return true;
            }
        }
    }

    return false; //default
}
2 of 16
77

All these answers are not allowed now. Here is the correct one:

For all those still looking for the Answer:

Here is how OLA Cabs and other such apps are doing it.

Add this in your onCreate

if (googleApiClient == null) {
    googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(LocationServices.API).addConnectionCallbacks(this)
            .addOnConnectionFailedListener(Login.this).build();
    googleApiClient.connect();
            LocationRequest locationRequest = LocationRequest.create();
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setInterval(30 * 1000);
    locationRequest.setFastestInterval(5 * 1000);
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(locationRequest);

    // **************************
    builder.setAlwaysShow(true); // this is the key ingredient
    // **************************

    PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi
            .checkLocationSettings(googleApiClient, builder.build());
    result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
        @Override
        public void onResult(LocationSettingsResult result) {
            final Status status = result.getStatus();
            final LocationSettingsStates state = result
                    .getLocationSettingsStates();
            switch (status.getStatusCode()) {
            case LocationSettingsStatusCodes.SUCCESS:
                // All location settings are satisfied. The client can
                // initialize location
                // requests here.
                break;
            case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                // Location settings are not satisfied. But could be
                // fixed by showing the user
                // a dialog.
                try {
                    // Show the dialog by calling
                    // startResolutionForResult(),
                    // and check the result in onActivityResult().
                    status.startResolutionForResult(Login.this, 1000);
                } catch (IntentSender.SendIntentException e) {
                    // Ignore the error.
                }
                break;
            case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                // Location settings are not satisfied. However, we have
                // no way to fix the
                // settings so we won't show the dialog.
                break;
            }
        }
    });
}

These are the implmented methods:

@Override
public void onConnected(Bundle arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onConnectionSuspended(int arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onConnectionFailed(ConnectionResult arg0) {
    // TODO Auto-generated method stub

}

Here is the Android Documentation for the same.

This is to help other guys if they are still struggling:

Edit: Adding Irfan Raza's comment for more help.

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     if (requestCode == 1000) {
         if(resultCode == Activity.RESULT_OK){
             String result=data.getStringExtra("result"); 
         } if (resultCode == Activity.RESULT_CANCELED) {
             //Write your code if there's no result 
         } 
    } 
} 
Top answer
1 of 7
22

No, it's impossible, and inappropriate. You can't just manage the user's phone without their authority. The user must interact to enable GPS.

From Play Store:

"Cerberus automatically enables GPS if it is off when you try to localize your device (only on Android < 2.3.3) and you can protect it from unauthorized uninstalling - more info in the app configuration."

You can do something like this:

startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
2 of 7
16

I think we have more better version to enable the location without opening the settings just like google map works.

It will looks like this -

Add Dependency in gradle - compile 'com.google.android.gms:play-services-location:10.0.1'

public class MapActivity extends AppCompatActivity {

    protected static final String TAG = "LocationOnOff";

 
    private GoogleApiClient googleApiClient;
    final static int REQUEST_LOCATION = 199;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.setFinishOnTouchOutside(true);

        // Todo Location Already on  ... start
        final LocationManager manager = (LocationManager) MapActivity.this.getSystemService(Context.LOCATION_SERVICE);
        if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER) && hasGPSDevice(MapActivity.this)) {
            Toast.makeText(MapActivity.this,"Gps already enabled",Toast.LENGTH_SHORT).show();
        }
        // Todo Location Already on  ... end

        if(!hasGPSDevice(MapActivity.this)){
            Toast.makeText(MapActivity.this,"Gps not Supported",Toast.LENGTH_SHORT).show();
        }

        if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER) && hasGPSDevice(MapActivity.this)) {
            Log.e("TAG","Gps already enabled");
            Toast.makeText(MapActivity.this,"Gps not enabled",Toast.LENGTH_SHORT).show();
            enableLoc();
        }else{
            Log.e("TAG","Gps already enabled");
            Toast.makeText(MapActivity.this,"Gps already enabled",Toast.LENGTH_SHORT).show();
        }
    }


    private boolean hasGPSDevice(Context context) {
        final LocationManager mgr = (LocationManager) context
                .getSystemService(Context.LOCATION_SERVICE);
        if (mgr == null)
            return false;
        final List<String> providers = mgr.getAllProviders();
        if (providers == null)
            return false;
        return providers.contains(LocationManager.GPS_PROVIDER);
    }

    private void enableLoc() {

        if (googleApiClient == null) {
            googleApiClient = new GoogleApiClient.Builder(MapActivity.this)
                    .addApi(LocationServices.API)
                    .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                        @Override
                        public void onConnected(Bundle bundle) {

                        }

                        @Override
                        public void onConnectionSuspended(int i) {
                            googleApiClient.connect();
                        }
                    })
                    .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
                        @Override
                        public void onConnectionFailed(ConnectionResult connectionResult) {

                            Log.d("Location error","Location error " + connectionResult.getErrorCode());
                        }
                    }).build();
            googleApiClient.connect();
         }

         LocationRequest locationRequest = LocationRequest.create();
            locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
         locationRequest.setInterval(30 * 1000);
         locationRequest.setFastestInterval(5 * 1000);
         LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
                    .addLocationRequest(locationRequest);

         builder.setAlwaysShow(true);

         PendingResult<LocationSettingsResult> result =
                    LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
         result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
            @Override
            public void onResult(LocationSettingsResult result) {
                final Status status = result.getStatus();
                switch (status.getStatusCode()) {
                  case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                       try {
                           // Show the dialog by calling startResolutionForResult(),
                           // and check the result in onActivityResult().
                                status.startResolutionForResult(MapActivity.this, REQUEST_LOCATION);
                       } catch (IntentSender.SendIntentException e) {
                           // Ignore the error.
                       }
                       break;
                 }
             }
         });
     }

}
🌐
Verizon
verizon.com › support › knowledge-base-106080
GPS Location Settings - Android | Verizon
Here's how to view / change GPS location settings, which can affect battery life and location accuracy.
Find elsewhere
🌐
Quora
quora.com › How-do-I-enable-GPS-on-my-Android-tablet
How to enable GPS on my Android tablet - Quora
Android (operating system... ... It may vary a bit depending on how old your tablet it but. You want to enter your device settings, newer device you can swipe down and click the the settings/gear icon.
🌐
OfficerReports
help.officerreports.net › support › solutions › articles › 61000222391-enable-gps-on-your-android-device
Enable GPS on your Android Device : OfficerReports
April 20, 2020 - When you first turn on your smartphone and you are taken through the setup process, you will undoubtedly be asked if you want to turn on location services. As you read the screen that talks about these location services, one that mentions GPS ...
🌐
Field Promax
fieldpromax.com › blog › how-to-turn-on-gps-in-2025
How to Turn On GPS in 2025: Easy Guides for Android & Tracking Tips
February 11, 2026 - Learn how to turn on GPS in 2025 for Android phones. Step-by-step setup, offline tips, and tracking features made simple.
🌐
Google Support
support.google.com › android › thread › 174443084 › how-to-turn-gps-on
How to turn GPS on - Android Community
August 9, 2022 - Skip to main content · Android Help · Sign in · Google Help · Help Center · Community · Android · Terms of Service · Submit feedback · Send feedback on
🌐
Medium
droidbyme.medium.com › android-turn-on-gps-programmatically-d585cf29c1ef
Android Turn on GPS programmatically | by Droid By Me | Medium
January 2, 2019 - GPS Dialog will be shown for SettingsClient’s failure callback and it will result in an activity’s onActivityResult(). So basically if the user agrees for turn on GPS, we can enable GPS flag in our activity.
🌐
Tech Advisor
techadvisor.com › home › how-to › phone how-to
Switch your GPS on and off easily on Android
September 7, 2016 - A lot of the best Android apps require your location to work fully and some even to work at all. The GPS in your phone can accurately locate your position so you can do all kinds of things. You might want to use a map, share your location with a friend or find what offers are nearby. Although this is generally for phones, some tablets feature GPS, too. When you open an app which requires GPS, it should ask you to enable ...
🌐
Progressionlive
go.progressionlive.com › help center › mobile interface › android
How to activate the GPS location service of an Android device for a specific app?
. 2. Tap on the ProgressionLIVE app. 3. Tap on Permissions, then Location. 4. Tap on Allow only when using the app. The location is now activated for the ProgressionLIVE app.
🌐
Droid Life
droid-life.com › home › tips and tricks › android beginners guide › how to: enable gps and other location services [beginners’ guide]
How to: Enable GPS and Other Location Services [Beginners’ Guide]
December 30, 2019 - When you first turn on your smartphone and you are taken through the setup process, you will undoubtedly be asked if you want to turn on location services. As you read the screen that talks about these location services, one that mentions GPS tracking... #Android #AndroidBeginnersGuideandTips
🌐
Alibaba
carinterior.alibaba.com › question › how-to-enable-gps-on-android
How to Turn on GPS on Android Phone: Step-by-Step Guide
January 17, 2026 - Tap Location or Security & Location, depending on your device model and Android version. Toggle the switch to turn Location on. Once enabled, you can customize how your phone determines location: Under the Location menu, tap Mode, Locating Method, or Accuracy (varies by brand): High Accuracy ✅ – Uses GPS, Wi-Fi, Bluetooth, and mobile networks.
Top answer
1 of 4
2

Implement LocationListener :

@Override
public void onLocationChanged(Location location) {

}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {

}

@Override
public void onProviderEnabled(String provider) {

}

@Override
public void onProviderDisabled(String provider)
{
    if (provider.equals(LocationManager.GPS_PROVIDER))
    {
        showGPSDiabledDialog();
    }
}     

Show dialog to open Settings:

public void showGPSDiabledDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("GPS Disabled");
    builder.setMessage("Gps is disabled, in order to use the application properly you need to enable GPS of your device");
    builder.setPositiveButton("Enable GPS", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), GPS_ENABLE_REQUEST);
        }
    }).setNegativeButton("No, Just Exit", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });
    mGPSDialog = builder.create();
    mGPSDialog.show();
}

In your onCreate Method call :

LocationManager mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    return;
}
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);

And override onActivityResult method to test if the user activated GPS correctly.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == GPS_ENABLE_REQUEST) {
        if (mLocationManager == null) {
            mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        }

        if (!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            showGPSDiabledDialog();
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
2 of 4
1

Full example :

/**
 * Function to check if best network provider
 * @return boolean
 * */
public boolean canGetLocation() {
    return this.canGetLocation;
}

/**
 * Function to show settings alert dialog
 * */
public void showSettingsAlert(){
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);

    // Setting Dialog Title
    alertDialog.setTitle("GPS is settings");

    // Setting Dialog Message
    alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");

    // Setting Icon to Dialog
    //alertDialog.setIcon(R.drawable.delete);

    // On pressing Settings button
    alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog,int which) {
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            mContext.startActivity(intent);
        }
    });

    // on pressing cancel button
    alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        dialog.cancel();
        }
    });

    // Showing Alert Message
    alertDialog.show();
}

Here is the doc : http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/ (copied point 7)

🌐
Samsung
samsung.com › home › product help & support › mobile phone › how to activate my location and change settings for location permissions
How to activate my location and change settings for location permissions | Samsung Caribbean
September 11, 2025 - To use location-based services and apps like Google maps on your Galaxy phone, you need to enable your device's GPS location settings. Your device may use a combination of Wi-Fi, GPS, and mobile networks to determine your location and even get help if your phone is lost or otherwise.