我和安卓系统中的位置侦听器有点纠结。我想做一个应用程序,将得到当前的全球定位系统的位置,然后再睡很长一段时间。一天或更多。在此期间,我希望GPS通知图标不显示。
我现在所做的,是在onlocationchanged a thread.sleep(x)中,但这将使图标在睡眠期间保持打开状态。我该怎么做呢,还有比使用thread.sleep更好的方法吗?
提前谢谢
最佳答案
为此,必须完全关闭LocationManager。我在我的应用程序中做到了,我每10秒只检查一次位置,因为我发现,关闭比LocationManager的最小距离或最小时间节省了一点电池电量。
类似于:
// Turning off
mLocationManager.removeUpdates(gpsListener);
mLocationManager = null;
// Turning on again
mLocationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_MINTIME, GPS_MINDISTANCE, gpsListener);
图标将消失,直到再次打开LocationManager。