views:

4217

answers:

4

I'm currently writing an app in Android that works with the GPS, at the moment I'm able to work out whether the GPS is enabled, my problem is that I want to enable the GPS on app startup if it is disabled, how can I do this programmaticaly?

+14  A: 

You can't, starting with Android 1.5. The most you can do is pop open the activity to allow the user to toggle it on/off. Use the action held in android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS to craft an Intent to open this activity.

CommonsWare
Why is this disabled? Why not allow developers to toggle this? the Power Control widget can, so we should be able to as well. Dont you think?
Adam Lerman
It is disabled for privacy reasons. If the user wants GPS off, the user should have GPS off, period.
CommonsWare
+4  A: 

if(!LocationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER )) {

Intent myIntent = new Intent( Settings.ACTION_SECURITY_SETTINGS ); startActivity(myIntent);

}

TS.xy
+1  A: 

is it possible to hack/root the phone in order to give this access right and turn on GPS programaticaly ? I also have same problem. Thanks, cheers!

Radus