0

Due to the battery drainage, i want to switch ON/OFF the providers programmatically that is background mode. Previously i did with settings activity of providers. But i feel it is not user friendly.

Please help me?

user1670564
  • 391
  • 2
  • 4
  • 12

1 Answers1

0

You can't control it at the system level. Only users are allowed to do that. But you can stop listening for GPS events using something like:

locationManager.removeUpdates(myLocationListener); 
locationManager = null;

You can also launch the settings screen so the user can do it himself using:

if(!LocationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER ))
{
    Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS );
    startActivity(myIntent);
}
Anup Cowkur
  • 20,443
  • 6
  • 51
  • 84