位置经理犯规删除位置更新! [英] Location manager doesnt remove location updates!
问题描述
可能重复:
<一href="http://stackoverflow.com/questions/3031630/android-how-to-cancel-a-request-of-location-update-with-intent">Android:如何取消意图位置更新请求?
我试图禁用挂起的意图(广播),我有一个不同的活动pviously创建$ P $,但我无法得到它的工作。我读过,我要重新创建的意图(具有相同的演员和一切),把它作为一个参数,这样我可以实例化pendingIntent再通过pendingIntent作为参数传递给位置经理removeUpdates方法。
I am trying to disable a pending intent(broadcast) which I have previously created in a different activity but I can't get it to work. I've read that I should recreate the intent(with the same extras and everything), pass it as a parameter so that I can instantiate the pendingIntent and then pass the pendingIntent as a parameter to the location managers removeUpdates method.
在换句话说:
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
这是没有工作,所以我认为这可能跟,即时通讯传递是一个新的对象,而不是相同的,以创造挂起的意图使用的一种意图。
That didn't work so I thought that it might have to do with the intent that im passing in being a new object and not the same with the one used in order to create the pending intent.
于是,我试图消除pendingIntent创建之后,但没有工作之一:
So I tried removing the pendingIntent right after I create it but that didnt work either:
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);
您可以请帮我带在于:它被窃听是因为周三...希望我有更多的信誉把boundy就这一个...
Can you please help me with that??? Its been bugging be since wednesday...wish i had more reputation to put a boundy on this one...
感谢
迈克
推荐答案
通过重建的意图,然后调用.cancel()上挂起的意图......解决它
Resolved it by recreating the intent and then calling .cancel() on the pending intent...
这篇关于位置经理犯规删除位置更新!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!