Android 谷歌地图和被动提供者
我正在使用被动提供者,使用此代码Android 谷歌地图和被动提供者,android,location,locationmanager,Android,Location,Locationmanager,我正在使用被动提供者,使用此代码 Intent intent = new Intent(PASSIVE_ACTION); PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE); mLocationManager.
Intent intent = new Intent(PASSIVE_ACTION);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
mLocationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, pi);
我在AndroidManifest.xml中定义了广播接收器
<receiver
android:name="passiveLocationReceiver"
android:enabled="true" >
<intent-filter>
<action android:name="com.passive_location_update" />
</intent-filter>
</receiver>
当使用其他地理位置应用程序(facebook、foursquare等)时,此代码工作正常
但在“谷歌地图”应用程序中,它并没有(解释了“被动地图提供者”,它可以在其他应用程序请求位置时更新)
虽然我可以通过“谷歌地图”应用程序查看我的位置,但我无法从被动提供商处获取任何事件。(我无法查看被动定位接收器的日志消息。)
我试图在命令行中转储LocationManager的状态
$adb shell dumpsys location
然而,LocationManager的状态没有改变任何事情。看起来像“谷歌地图”应用程序
不使用LocationManager
当“谷歌地图”应用程序更新我的位置时,有没有办法获得被动事件??
或者我做错了什么???RequestLocationUpdate将只接收位置值的更改或“更新”。谷歌地图将广播GPS位置提供商提供的位置值变化 如果从模拟器进行测试,请尝试为模拟位置输入新值。否则,请边走边测试 然而,我也注意到,Wi-Fi(网络)位置的变化不会像其他类似应用程序一样从谷歌地图上广播
在您的情况下-可能GPS没有启用,或者它没有从当前状态更改位置,因此您没有收到此侦听器位置的任何“更新”。(我找到这个话题是因为我想知道,如果有人知道的话,为什么谷歌地图不广播Wi-Fi位置更改)最近的谷歌地图和其他地图服务使用基于谷歌播放服务的新版本位置API。他们不仅依赖GPS或网络供应商,还使用“融合”的GPS或网络供应商。由于这个原因,传统被动_提供程序无法使用“fused”方法捕获位置更新 您最好将新API与LocationClient和LocationRequest一起使用,并具有优先权。检查以下代码
LocationRequest lRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_NO_POWER)
.setInterval(mMIN_LOCATION_UPDATE_INTERVERAL_IN_MILLISECONDS);
Intent locationIntent = new Intent(mPASSIVE_LOCATION_INTENT_ACTION_STRING);
mPassiveLocationPendingIntent = PendingIntent.getBroadcast(mContext, 0, locationIntent ,PendingIntent.FLAG_UPDATE_CURRENT);
mPassiveLocationClient.requestLocationUpdates(lRequest, mPassiveLocationPendingIntent);
... 但是,您无法判断该位置是否来自GPS、网络或带有融合位置的WiFi。
LocationRequest lRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_NO_POWER)
.setInterval(mMIN_LOCATION_UPDATE_INTERVERAL_IN_MILLISECONDS);
Intent locationIntent = new Intent(mPASSIVE_LOCATION_INTENT_ACTION_STRING);
mPassiveLocationPendingIntent = PendingIntent.getBroadcast(mContext, 0, locationIntent ,PendingIntent.FLAG_UPDATE_CURRENT);
mPassiveLocationClient.requestLocationUpdates(lRequest, mPassiveLocationPendingIntent);