1

Possible Duplicate:
Enable GPS programatically like Tasker

I would like to know how to turn on the GPS inside the code ? someone says you cannot and other says you can, I get confused Pleas help me,

Community
  • 1
  • 1
Dev
  • 199
  • 1
  • 3
  • 10
  • I presume that what you mean is "enable GPS". Turning it on is simply a matter of using some `LocationManager` method to ask for GPS fixes (e.g., `requestLocationUpdates()`), which only works if GPS is enabled. All known security flaws that other people were suggesting to enable GPS are now fixed. – CommonsWare Aug 27 '11 at 18:09

1 Answers1

5

Turning the GPS on requires user interaction as a security measure. If any application were able to turn the GPS on without the user knowing, that would be a very big privacy concern.

You can launch an Intent that takes the user to the GPS screen to turn it on / off.

startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));

Jason Knight
  • 5,824
  • 1
  • 16
  • 14
  • 3
    Wrong activity action, I think -- `ACTION_LOCATION_SOURCE_SETTINGS` – CommonsWare Aug 27 '11 at 18:08
  • 1
    I asked myself the same thing a couple of months ago, but then realized it would be a HUGE privacy concern for me to enable GPS without user interaction. – Jack Aug 27 '11 at 18:08
  • I'd been sending my app to that system config screen with 'new intent(Settings.ACTION_SECURITY_SETTINGS)', as per the original answer. ACTION_LOCATION_SOURCE_SETTINGS seems to send it to the same screen (at least on the emulator it does) - I'm wondering what the difference is? – NickT Aug 27 '11 at 19:21
  • **This is possible. Check this** [link] (http://stackoverflow.com/questions/4721449/enable-gps-programatically-like-tasker) – Atul Bhardwaj Jul 18 '12 at 05:53