0

Possible Duplicate:
Enable GPS programatically like Tasker

All,

I seen most of the answers in this forum that we CANT turn on gps programmatic ally. I am wondering in some of the applications available in Android market, how do they do? I tried most of the things explained in this forum, it always gives a prompt to the user to enable the Location based services.

Any other thoughts?

Thanks, Ramesh

Community
  • 1
  • 1
Ramesh Sangili
  • 1,633
  • 3
  • 17
  • 31
  • 3
    Duplicate question. Short answer. Not possible programatically. – smk Nov 15 '12 at 20:41
  • What application have you seen that does that? None do. – Madbreaks Nov 15 '12 at 20:42
  • If GPS is already enabled, it can start up GPS programatically. If GPS is not enabled, you cannot enable it on any recent version of Android. Older versions (think 1.6) allowed you to do so, but not anymore. – Gabe Sechan Nov 15 '12 at 20:44

2 Answers2

0

Not sure what you mean by "turn it on". Do you mean enable or disable it? This thread discusses some ways to enable or disable it by exploiting bugs: How can I enable or disable the GPS programmatically on Android?. I wouldn't use this method though, since it won't work on devices where the bug has been fixed. Far better to forward the user to the settings app and let them enable gps.

Do you mean to turn it on or off to use it, assuming it's been enabled? You don't need to do that. Simply call LocationManager.requestLocationUpdates() with the right location provider, and the system will turn it on for you.

Community
  • 1
  • 1
Edward Falk
  • 9,991
  • 11
  • 77
  • 112
  • I am trying to enable to Location Services once I receives a SMS. I am planning to do a simple application to check where my wife is currently located, incase if she turns off her gps, I wnated to enable it programmatically without any manual intervention and fetch the co ordinates and send it back to me. Hope you are clear now – Ramesh Sangili Nov 20 '12 at 22:15
-2

Have you looked here?

http://developer.android.com/guide/topics/location/strategies.html

What you can do is assert what type of location provider is enabled, check if it is GPS, if not add this to prompt the user to turn on GPS (be sure to run a long Toast to let the user know to enable GPS location and to hit the back button once enabled):

  ComponentName intentComponent = new ComponentName("com.android.settings", "com.android.settings.LocationSettings");
          Intent mainIntent = new Intent("android.intent.action.MAIN");
          mainIntent.setComponent(intentComponent);
          startActivity(mainIntent);
childofthehorn
  • 697
  • 1
  • 4
  • 12