由于电池耗尽,我想以编程方式打开/关闭提供程序,即后台模式。以前我做过提供者的设置活动。但我觉得它对用户不友好。
请帮我?
您无法在系统级别控制它。只有用户被允许这样做。但是您可以使用以下方式停止侦听 GPS 事件:
locationManager.removeUpdates(myLocationListener);
locationManager = null;
您还可以启动设置屏幕,以便用户可以自己使用:
if(!LocationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER ))
{
Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS );
startActivity(myIntent);
}