位置管理员不会删除位置更新!

时间:2011-02-11 07:14:39

标签: android geolocation android-intent locationmanager android-pendingintent

  

可能重复:
  Android: how to cancel a request of Location update with intent?

我正在尝试禁用我之前在其他活动中创建的待处理意图(广播),但我无法让它工作。我已经读过我应该重新创建intent(使用相同的附加内容和所有内容),将其作为参数传递,以便我可以实例化pendingIntent,然后将pendingIntent作为参数传递给位置管理器removeUpdates方法。

换句话说:


Bundle extra = new Bundle();

extra.putString("name", extras.getString("poiName")); //create same extras

extra.putInt("id", extras.getInt("rowId")); //create same extras

Intent intent = new Intent(PROX_ALERT_INTENT);  

intent.putExtra(PROX_ALERT_INTENT, extra);  //put same extras in the intent

PendingIntent proximityIntent = PendingIntent.getBroadcast(this.getApplicationContext(),extras.getInt("rowId") , intent, PendingIntent.FLAG_UPDATE_CURRENT);  //pass in the intent

LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
                                               locationManager.removeUpdates(proximityIntent);  //remove pendingIntent

这没有用,所以我认为它可能与我传入新对象的意图有关,而与用于创建待处理意图的意图不一样。

所以我尝试在创建之后立即删除pendingIntent但是它也没有工作:

Bundle extras = new Bundle();

    extras.putString("name", poiName);

    extras.putInt("id", requestCode);

    Intent intent = new Intent(PROX_ALERT_INTENT);

    intent.putExtra(PROX_ALERT_INTENT, extras);

    PendingIntent proximityIntent = PendingIntent.getBroadcast(this.getApplicationContext(), requestCode , intent, PendingIntent.FLAG_CANCEL_CURRENT);

    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
   );
    locationManager.removeUpdates(proximityIntent);

你能帮帮我吗???自从周三以来它一直在喋喋不休...希望我有更多的声誉来对这个问题施加影响......

由于

麦克

1 个答案:

答案 0 :(得分:4)

通过重新创建intent然后在挂起的intent ...上调用.cancel()来解决它...

相关问题