アプリケーションで複数のおおよそのアラートを設定しました。私はこのように通知を設定します:
private void addProximityAlert(double latitude, double longitude) {
try{
LatLonPair latLon;
for(int i = 0; i < mPositions.size(); i++) {
latLon = mPositions.get(i);
Intent intent = new Intent(PROXIMTY_ALERT_INTENT);
intent.putExtra(ProximityIntentReceiver.EVENT_ID_INTENT_EXTRA, i);
intent.putExtra(ProximityIntentReceiver.ITEM_NAME,latLon.getItemName());
intent.putExtra(ProximityIntentReceiver.PLACE_NAME,latLon.getPlaceName());
PendingIntent proximityIntent = PendingIntent.getBroadcast(this, i, intent, 0);
locationManager.addProximityAlert(latLon.getLatitude(), latLon.getLongitude(), radius, expiration, proximityIntent);// alerts set here.
IntentFilter filter = new IntentFilter(PROXIMTY_ALERT_INTENT);
registerReceiver(new ProximityIntentReceiver(), filter);
}
}
catch(Exception ex){
ex.toString();
}
}
保存されているすべての位置は、一度に近接アラートに登録されます。1 つの通知が発生し、指定された半径内で再び発火し続けると、そこで何が起こったのかがわかりました。デバイスがまだ定義済みの半径にあるときに、一度発生したアラートを削除する方法が何度も何度も通知されないようにする必要があります。