Android的:如何取消位置更新的意图的要求?意图、位置、Android

2023-09-04 12:50:28 作者:承欢

我注册了一个PendingIntent到requestLocationUpdates(供应商,minTime,minDistance依旧,PendingIntent)。但是,当我的广播接收器接收到这个打算,我怎么删除此请求,removeUpdates(PendingIntent)?接收器无法保持参照原有PendingIntent。

I registered a PendingIntent to requestLocationUpdates(provider, minTime, minDistance, PendingIntent). But when my broadcast receiver receives this intend, how do I remove this request with removeUpdates(PendingIntent)? The receiver doesn't hold a reference to the original PendingIntent.

推荐答案

您创建一个等效 PendingIntent 。换句话说,创建一个意图匹配您最初使用(虽然你可以跳过任何额外的)一个,包在同一类 PendingIntent的您最初使用,并使用 PendingIntent removeUpdates()通话。

You create an equivalent PendingIntent. In other words, create an Intent that matches the one you used originally (though you can skip any extras), wrap that in the same sort of PendingIntent that you used originally, and use that PendingIntent in the removeUpdates() call.

 
精彩推荐
图片推荐