Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically enable GPS in Android Cupcake

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?

like image 517
Chiwai Chan Avatar asked Jun 26 '09 23:06

Chiwai Chan


2 Answers

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.

like image 50
CommonsWare Avatar answered Oct 02 '22 03:10

CommonsWare


if(!LocationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER )) {     Intent myIntent = new Intent( Settings.ACTION_SECURITY_SETTINGS );     startActivity(myIntent); } 
like image 27
TS.xy Avatar answered Oct 02 '22 02:10

TS.xy