2

With a button click how can we enable and disable GPS programmatically.

When we click the button for the first time we should enable the GPS , on second click on the same button we should disable the GPS

I searched for the related threads but I didn't find any solution

Please share some related links/code

Any help is always appreciated, Thanks

Randroid
  • 3,688
  • 5
  • 30
  • 55

1 Answers1

3

With a button click how can we enable and disable GPS programmatically.

Fortunately, you can't anymore, for privacy reasons.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for the reply, I saw the same functionality in LG mobile. I thought of doing that. – Randroid Jun 12 '12 at 13:46
  • Is it possible in any other way?I mean navigating to GPS settings page – Randroid Jun 12 '12 at 13:49
  • 1
    @Raghav: You can navigate the user to the Location page in the Settings app, at least on most devices. `startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS))` should do it. – CommonsWare Jun 12 '12 at 16:36
  • @CommonsWare quite old answer, I saw a few days back google maps is doing this on a button click. Any idea how they are doing it? – Akram Apr 08 '15 at 05:33
  • @Akram: If you are using Google Play Services, they have a largely-undocumented `SettingsApi` that appears to be how you do this: https://developer.android.com/reference/com/google/android/gms/location/SettingsApi.html – CommonsWare Apr 08 '15 at 10:47