Android的:如何在我的位置设置位置服务启用或禁用用户得到注意 [英] android :how to get noticed when the My Location setting location service is enabled or disabled by user

查看:566
本文介绍了Android的:如何在我的位置设置位置服务启用或禁用用户得到注意的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在后台只要设备被引导运行的定位服务。我要求网络和全球定位系统提供者更新通过调用的LocationManager requestLocationUpdate方法,然而,当在我的位置设置页由启用或禁用定位服务改变,则onProviderEnabled或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 ?

推荐答案

是的,你可以实现你的服务中扩展广播接收器类侦听开启/关闭广播GPS。当GPS开启或关闭,虽然,它不会调用onProviderEnabled()方法中,它调用GpsStatus.OnGpsStatusChanged()方法。

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.

当GPS改变发送的广播活动的值:

The broadcast sent when the GPS is changed has event values:

GPS_EVENT_STARTED
GPS_EVENT_STOPPED

GPS_EVENT_STARTED GPS_EVENT_STOPPED

查看广播接收器 API关于如何实现广播接收机。

See the BroadcastReceiver API on how to implement a Broadcast Receiver.

这篇关于Android的:如何在我的位置设置位置服务启用或禁用用户得到注意的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆