[英]How to listen for location providers becoming enabled / disabled?
是否可以在启用或禁用位置提供程序时得到通知,而无需实际查找设备的位置(因为这样做可能会消耗大量电能)?
In android there is LocationListener interface which provides a abstract method onProviderEnabled(String provider). 在android中,有LocationListener接口,它提供了onProviderEnabled(String provider)的抽象方法。 So you have create your own listener and implement the onProviderEnabled(String provider) method. 因此,您已经创建了自己的侦听器并实现onProviderEnabled(String provider)方法。 It is very must your listener must be register with location manager. 您的听众必须在位置管理器中注册,这是非常必要的。
If do same as described above then onProviderEnabled(String provider) will called automatically when location provider became enable. 如果执行与上述相同的操作,则在启用位置提供程序后会自动调用onProviderEnabled(String provider)。
Locationmanager.isProviderEnabled() doesn't seem to require actually looking up the location. Locationmanager.isProviderEnabled()似乎不需要实际查找位置。 It won't be too efficient as you'd need to poll it, but it's better than getting the actual location. 它不会很高效,因为您需要对其进行轮询,但是比获取实际位置要好。
Actually, reading a bit more on the topic, it seems you'd be able to use requestLocationUpdates() to do this. 实际上,阅读有关该主题的更多内容,看来您可以使用requestLocationUpdates()来完成此操作。 It will send you a bundle with KEY_PROVIDER_ENABLED
when the provider is enabled or disabled. 启用或禁用提供程序时,它将向您发送包含KEY_PROVIDER_ENABLED
的捆绑KEY_PROVIDER_ENABLED
。 You can set the minimum time and distance for notification to extremely high values. 您可以将通知的最短时间和距离设置为极高的值。 This way you'll get a location notification once in a while and mostly just enabled/disabled notifications. 这样,您会偶尔收到一次位置通知,并且大多数情况下只是启用/禁用了通知。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.