Search code examples
androidpermissionsandroid-permissionsandroid-location

What is the Action/Intent to turn ON Location (GPS)


I would like to know the Intent command for Turning ON GPS automatically. I'm developing an Android app, and would like to enable the GPS without navigating to the settings page (Something similar to UBER). I'm looking for the Action/Intent that would trigger the LOCATION_ENABLE settings.

EX: android.settings.LOCATION_SOURCE_SETTINGS_ENABLE (Something similar to This)


Solution

  • You can not enable user's location automatically but you need to request to users if they want to grant location permission to your app.

    You will display a dialog to user explaining why do you need permission and depending upon user's interest they can enable or disable it.

    For how to request location permission, please have a look at this question

    Update:

    To open native GPS Settings you can use Settings.ACTION_LOCATION_SOURCE_SETTINGS action like below:

    final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    startActivity(intent);