我以这种方式创建接近警报
private void setProximityAlert(float radius, double lat, double lng, String place)
{
long expiration = -1;
LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Intent intent = new Intent(TREASURE_PROXIMITY_ALERT);
intent.putExtra("lat", lat);
intent.putExtra("lng", lng);
intent.putExtra("place", place);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), -1, intent, 0);
locManager.addProximityAlert(lat, lng, radius, expiration, pendingIntent);
}
在我的活动中,我以这种方式注册了接收器
IntentFilter intentFilter = new IntentFilter(TREASURE_PROXIMITY_ALERT);
registerReceiver(new ProximityIntentReceiver(), intentFilter);
setProximityAlert(10, 45.150344, 9.999815, "POINT1");
并且我的广播接收器被正确调用。所以现在,我想添加另一个接近警报,可以吗?我希望 2 个接近警报调用同一个广播接收器。我做的:
IntentFilter intentFilter1 = new IntentFilter(TREASURE_PROXIMITY_ALERT1);
registerReceiver(new ProximityIntentReceiver(), intentFilter1);
setProximityAlert(200f, 45.143848, 10.039741, "POINT2");
但它不起作用,什么也没有发生。我现在真的很喜欢它,我想知道这是否是正确的方法。我的意图是触发 2 个警报,一个在 GPS 获得位置 POINT1 时触发,另一个在位置 POINT2 时触发。欢迎任何帮助。