android - 实现 GPS 时如何避免电池耗尽?

标签 android

在我的应用程序中,我使用了 GPS 监听器。我需要关闭 GPS,稍后再激活它。目前我正在使用

locationManager.removeUpdates(locationListener);

关闭GPS。这将关闭 GPS。但是后来我无法打开它?有没有其他方法可以关闭gps?

用于激活我正在使用的 GPS

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updatesInterval, 0, locationListener);

最佳答案

您可以创建一个实现位置监听器的服务 所以当你想启动位置监听器时,你可以启动服务并放置

ocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updatesInterval, 0, locationListener);

onCreate() 方法中的行

当你想关闭位置更新停止服务 放线

locationManager.removeUpdates(locationListener);

onDistroy() 方法

关于android - 实现 GPS 时如何避免电池耗尽?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5964925/

相关文章:

android - 如何为 Android 创建安全的在线数据库

java - 无法让嵌套 fragment 工作,无法解析 getChildFragmentManager

android - 从内存中打开 PNG 文件并通过 TCP 套接字发送

android - 仅在按下完成按钮时获取 DatePickerDialog 值

android - 如何在三星智能电视上调试 Android 应用程序

android - Intent 过滤器 url 在标签后被截断

android - 异常后如何继续运行 Android 仪器测试?

android - 如何检测 libgdx 中的 Actor 何时被触摸?

android - 约束布局 : center view on full screen but limit width to not overlap with side views

android - 将横幅放在选项卡主机下方,仅用于一项 Activity