android:当用户启用或禁用“我的位置”设置位置服务时如何引起注意
只要设备启动,我就有一个位置服务在后台运行。我通过调用 LocationManager requestLocationUpdate 方法请求网络和 GPS 提供商更新,但是,当通过启用或禁用位置服务更改“我的位置”设置页面时,永远不会调用 onProviderEnabled 或 on ProviderDisabled。所以我想知道每次用户更改位置设置时我的后台服务如何收到通知?我可以在缓存广播消息的接收器模式下执行此操作吗?
I have a Location service that runs in the background as long as the the device is booted. I requested the network and gps provider update by calling LocationManager requestLocationUpdate method, however, when the My Location setting page is changed by enabling or disabling the location service, the onProviderEnabled or on ProviderDisabled are never called. So I want to know how could my background service got notified everytime the user changes the location setting? Can I do it in a receiver mode which caches the broadcast message ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以在您的服务中实现一个扩展的 BroadcastReceiver 类来侦听 GPS 开/关广播。但是,当 GPS 打开或关闭时,它不会调用 onProviderEnabled() 方法,而是调用 GpsStatus.OnGpsStatusChanged() 方法。
GPS改变时发送的广播具有事件值:
GPS_EVENT_STARTED
GPS_EVENT_STOPPED
请参阅 BroadcastReceiver API 了解如何实现广播接收器。
Yes, you can implement an extended BroadcastReceiver class within your service that listens for the GPS on/off broadcast. When the GPS is turned on or off though, it doesn't call the onProviderEnabled() method, it calls the GpsStatus.OnGpsStatusChanged() method.
The broadcast sent when the GPS is changed has event values:
GPS_EVENT_STARTED
GPS_EVENT_STOPPED
See the BroadcastReceiver API on how to implement a Broadcast Receiver.