我正在制作一个应用程序,只要用户/设备接近预定义的兴趣点之一,它就会显示警报。
我发现这样做的唯一方法(实际上我让它像那样工作)是为每个兴趣点创建一个待处理的意图(具有唯一的名称)。但我认为就资源而言,这不是最好的方法。
是否可以仅使用一个待定意图而不是多个单独的意图来实现此类功能?
还有其他更好的方法吗?
提前致谢
麦克风
private void addProximityAlert(double latitude, double longitude, String poiName) {
Bundle extras = new Bundle();
extras.putString("name", poiName);
Intent intent = new Intent(PROX_ALERT_INTENT+poiName);
intent.putExtras(extras);
PendingIntent proximityIntent = PendingIntent.getBroadcast(MainMenu.this, 0, intent, 0);
locationManager.addProximityAlert(
latitude, // the latitude of the central point of the alert region
longitude, // the longitude of the central point of the alert region
POINT_RADIUS, // the radius of the central point of the alert region, in meters
PROX_ALERT_EXPIRATION, // time for this proximity alert, in milliseconds, or -1 to indicate no expiration
proximityIntent // will be used to generate an Intent to fire when entry to or exit from the alert region is detected
);
IntentFilter filter = new IntentFilter(poiName);
registerReceiver(new ProximityIntentReceiver(), filter);
}
}