[英]android :how to get noticed when the My Location setting location service is enabled or disabled by user
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.
我通过调用LocationManager requestLocationUpdate方法请求网络和gps提供程序更新,但是,当通过启用或禁用位置服务更改“我的位置”设置页时,永远不会调用onProviderEnabled或ProviderDisabled。 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 ?
我可以在接收广播消息的接收器模式下执行此操作吗?
Yes, you can implement an extended BroadcastReceiver class within your service that listens for the GPS on/off broadcast. 是的,您可以在服务中实现扩展的BroadcastReceiver类,以侦听GPS开/关广播。 When the GPS is turned on or off though, it doesn't call the onProviderEnabled() method, it calls the GpsStatus.OnGpsStatusChanged() method.
但是,当GPS打开或关闭时,它不会调用onProviderEnabled()方法,而是会调用GpsStatus.OnGpsStatusChanged()方法。
The broadcast sent when the GPS is changed has event values: 更改GPS时发送的广播具有事件值:
GPS_EVENT_STARTED GPS_EVENT_STOPPED GPS_EVENT_STARTED GPS_EVENT_STOPPED
See the BroadcastReceiver API on how to implement a Broadcast Receiver. 有关如何实现广播接收器的信息,请参见BroadcastReceiver API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.