What is the meaning of android.location.LocationManager.PASSIVE_PROVIDER?

回眸只為那壹抹淺笑 提交于 2019-12-21 04:13:20

问题


I understand the meaning of GPS_PROVIDER (locations come from GPS signals) and NETWORK_PROVIDER (locations are determined from cell towers and wireless access points), but I don't understand the meaning of PASSIVE_PROVIDER, despite the definition in the API:

A special location provider for receiving locations without actually initiating a location fix. This provider can be used to passively receive location updates when other applications or services request them without actually requesting the locations yourself. This provider will return locations generated by other providers. You can query the getProvider() method to determine the origin of the location update. Requires the permission android.permission.ACCESS_FINE_LOCATION, although if the GPS is not enabled this provider might only return coarse fixes.

Why would one use this instead of one of the other providers? To save battery life? Does the passive provider only return useful information if some other app explicitly requests data from the real providers, or is it always safe to request locations from this?


回答1:


This provider is useful for services that work with the users location but don't want to waste battery life as you pointed out.

For example Google Latitude sends your current location to a web service to let your friends know where you are. If this service would request a GPS fix every 5 minutes the device battery will be empty very fast. If the service requests a passive location provider a location is send every time Google maps is started and a fix aquired or some other apps initiates a location provider update and the service can act on location data without spending additional power on the location updates.

If you need correct location data at an exact moment using this provider won't help. For most things that are not running in a background service this location provider is useless because it will only send updates if other apps trigger an update of the user location.




回答2:


To add to @Janusz, when you receive a fix due to someone else's provider and you wish to know from what provider is this fix from (NETWORK or GPS), you can call the getProvider() to find this.



来源:https://stackoverflow.com/questions/5655241/what-is-the-meaning-of-android-location-locationmanager-passive-provider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!