Android GPS enable programmatically [duplicate]
Possible Duplicate:
How can I enable or disable the GPS programmatically on Android?
I want to get lati开发者_开发技巧tude and longitude programmatic in Android app. But it depended upon whether the GPS is enabled or not. I used to check the GPS with this code
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
{
if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER ))
{
Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS );
startActivity(myIntent);
}
}
But it basically shows the screen to enable it. But I don't want that user should enable it. It should enable automatically if the gps is disabled.
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.
精彩评论