【发布时间】:2012-03-08 15:24:24
【问题描述】:
我正在与被动提供商合作,使用此代码。
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>
passiveLocationReceiver 是
public class passiveLocationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (!PASSIVE_ACTION.equals(action))
return;
Log.d("chitacan","Passive Provider Event!!!");
}
}
此代码在其他地理位置应用程序(facebook、foursquare.. 等)时可以正常工作 但是对于“谷歌地图”应用程序,它不会。(d.android.com 解释了当其他应用程序请求位置时可以更新的“PASSIVE_PROVIDER”。)
虽然我可以通过“谷歌地图”应用程序看到我的位置,但我无法从被动提供者那里获得任何事件。(我看不到passiveLocationReceiver 的日志消息。)
好吧,我尝试在命令行中转储 LocationManager 的状态,
$adb shell dumpsys location
但是 LocationManager 的状态并没有改变任何东西。看起来像“谷歌地图”应用程序 不使用 LocationManager。
当“谷歌地图”应用程序更新我的位置时,有没有办法获得被动事件? 还是我做错了什么??
【问题讨论】:
标签: android location locationmanager