【发布时间】:2011-02-08 23:43:43
【问题描述】:
我正在制作一个应用程序,只要用户/设备接近预定义的兴趣点之一,它就会显示警报。
我发现这样做的唯一方法(实际上我是这样工作的)是为每个兴趣点创建一个待处理的意图(具有唯一的名称)。但我认为这不是资源方面的最佳方式..
是否有可能只使用一个待定意图而不是多个单独的意图来实现这样的功能?
还有其他更好的方法吗?
提前致谢
迈克
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);
}
}
【问题讨论】:
-
向我们展示一个代码 sn-p... 你对待处理的意图做了什么?
-
@Mayra 刚刚编辑了帖子...看看...然后我有一个扩展 BroadcastReceiver 的类,它负责接收广播:) 并设置和显示警报...
标签: android android-intent android-pendingintent proximity point-of-interest