gpt4 book ai didi

android - 位置管理器不会删除位置更新!

转载 作者:搜寻专家 更新时间:2023-11-01 08:15:57 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Android: how to cancel a request of Location update with intent?

我正在尝试禁用我之前在不同 Activity 中创建的未决 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

那行不通,所以我认为这可能与我作为一个新对象传递的 Intent 有关,而不是与用于创建待定 Intent 的 Intent 不同。

所以我尝试在创建 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);

你能帮我解决这个问题吗???从星期三开始就一直在窃听...希望我有更多的声誉来限制这个...

谢谢

迈克

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com