How to programmatically enable GPS in Android Cupcake

Chiwai Chan picture Chiwai Chan · Jun 27, 2009 · Viewed 55.2k times · Source

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?

Answer

CommonsWare picture CommonsWare · Jun 27, 2009

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.