Thi*_*kel 1 android android-emulator
通过注册一组给定坐标的接近警报后
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Intent intent = new Intent(Constants.ACTION_PROXIMITY_ALERT);
intent.putExtra(Constants.INTENT_EXTRA_LOCATION, location); // custom payload
PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, 0);
locationManager.addProximityAlert(location.getLatitude(),
location.getLongitude(), location.getRadius(), -1, pendingIntent);
Run Code Online (Sandbox Code Playgroud)
在进入或离开配置的位置时,我会将意图传递给我的服务.到现在为止还挺好.
不幸的是,这些传递的意图中没有一个带有LocationManager.KEY_PROXIMITY_ENTERING标识位置变化类型(进入或退出)的布尔额外值,可以通过它来检索Intent.getBooleanExtra.我的观察是基于AOSP 2.1和AOSP 2.2.根据文档,这个额外应该总是存在.
有什么我错过的吗?在模拟器上使用模拟位置运行时,是否存在对此额外的限制?
事实证明,这似乎是由于在PendingIntent中添加了一个额外的可序列化额外内容.作为一种变通方法,如果需要额外的有效负载,可以自己执行序列化,或者只存储基本类型或字符串.