0
我正在製作一個應用程序,該應用程序在用戶/設備接近其中一個預定義興趣點時應該顯示警報。Android位置感知應用程序 - 設置多個興趣點而不使用多個監聽器
我發現這樣做的唯一方法(實際上我的工作就是這樣)是爲每個感興趣的點創建一個未決意圖(具有唯一的名稱)。但我認爲這不是在資源方面做到這一點的最佳方式。
是否有可能僅使用一個掛起的intend而不是多個單獨的intend來實現此功能?
還有其他更好的方法嗎?
在此先感謝
邁克
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);
}
}
向我們展示一個代碼片段...你對待處理意圖做什麼? – 2011-02-08 23:52:23