0

我正在制作一个应用程序,只要用户/设备接近预定义的兴趣点之一,它就会显示警报。

我发现这样做的唯一方法(实际上我让它像那样工作)是为每个兴趣点创建一个待处理的意图(具有唯一的名称)。但我认为就资源而言,这不是最好的方法。

是否可以仅使用一个待定意图而不是多个单独的意图来实现此类功能?

还有其他更好的方法吗?

提前致谢

麦克风


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);

    }
}
4

1 回答 1

1

得到它的工作......不要如果它是最好的方法做到这一点,但无论如何......

解决方案:http ://www.gauntface.co.uk/pages/blog/2010/01/04/proximity-alerts-in-android/

My Solution: Can a broadcastReceiver catch multiple broadcasts?

于 2011-02-10T00:42:15.180 回答