我在Android中的LocationListener上苦苦挣扎.我想制作一个可以获得当前GPS位置的应用程序,然后再睡一段时间.一天或更长时间.在这段时间里,我想要不显示GPS通知图标.
我现在拥有的是onLocationChanged一个Thread.sleep(x),但是这会在睡眠期间保持图标.我怎么能这样做,有没有比使用Thread.sleep更好的方法?
提前致谢
为此,您必须完全关闭 LocationManager。我在我的应用程序中做到了这一点,我只每 10 秒检查一次位置,因为我发现,关闭比 LocationManager 的 min_distance 或 min_time 节省更多电池电量。
就像是:
// 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);
Run Code Online (Sandbox Code Playgroud)
该图标将消失,直到位置管理器再次打开。
| 归档时间: |
|
| 查看次数: |
4528 次 |
| 最近记录: |