1

Possible Duplicate:
How can I enable or disable the GPS programmatically on Android?

I want to get latitude 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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
vivek_Android
  • 1,697
  • 4
  • 26
  • 43

1 Answers1

2

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.

Umesh K
  • 13,436
  • 25
  • 87
  • 129