【问题标题】:Android location aware app - Set multiple points of interest without using multiple listenersAndroid 位置感知应用 - 在不使用多个侦听器的情况下设置多个兴趣点
【发布时间】: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


【解决方案1】:

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

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

我的解决方案:Can a broadcastReceiver catch multiple broadcasts?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-01
    • 1970-01-01
    • 2018-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多