简体   繁体   English

android:当用户启用或禁用“我的位置”设置位置服务时如何引起注意

[英]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.

相关问题 如果禁用,Android获取位置或提示以启用位置服务 - Android get location or prompt to enable location service if disabled 用户启用位置服务后如何获得通知 - How to get notify when user has enabled Location services 禁用所有位置提供程序后,如何在android中获取位置? - How can you get a location in android when all location providers are disabled? 使用融合位置提供程序获取启用/禁用位置服务的信息 - Get information of Location Services enabled/disabled using Fused Location Provider 如何侦听启用/禁用的位置提供程序? - How to listen for location providers becoming enabled / disabled? Android Geofence禁用/重新启动位置服务时自动删除 - Android Geofence Automatically removed when location service is disabled / restarted 当应用程序具有服务后台时如何获取用户位置? - How To Get User Location when App is Background with Service? android位置-应用程序处于后台状态时无法在服务中获取位置 - android location - cannot get location in service when app is background IsProviderEnabled始终返回true启用或禁用位置服务 - IsProviderEnabled always return true either Location service is enabled or disabled 在用户位于Android中我的位置时通知 - Notify when user is in my location in Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM