[英]Remove proximity alert inside broadcast receiver android
嗨,我正在開發小型Android應用程序,其中正在使用接近警報。 因此,一切正常。 現在,我想在輸入事件觸發后立即執行的操作,就是要刪除該警報。 怎么做? 我可以在廣播接收器或其他地方執行此操作嗎? 我的代碼看起來像。
// in abc class
PendingIntent proximityIntent = PendingIntent.getBroadcast(
context, 0, intent,
PendingIntent.FLAG_CANCEL_CURRENT);
locationManager.addProximityAlert(
latitude,
longitude,
POINT_RADIUS,
PROX_ALERT_EXPIRATION,
proximityIntent );
// this is broadcast receiver
public void onReceive(Context context, Intent intent) {
String key = LocationManager.KEY_PROXIMITY_ENTERING;
Boolean entering = intent.getBooleanExtra(key, false);
if (entering)
{
// here I want to stop this alert... ANy solution how to stop this
}
else
{
}
}
怎么做? 需要幫忙。 謝謝。
使用LocationManager。 removeProximityAlert(PendingIntent)。 只需按照您傳遞給addProximityAlert的意圖傳遞它即可。 如果您現在沒有保存該文件,則必須將其保存到“活動/服務”中的變量中。
以我的經驗,待定意圖有一個不同的標志:
PendingIntent proximityIntent = PendingIntent
.getBroadcast(
NotificationService.this,
0,
intent,
PendingIntent.FLAG_ONE_SHOT);
當通知被看到,丟棄或使用時,我得到了以下代碼:
((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
.cancel(NOTIFICATION_ID);
在您的代碼中,通知ID為0。 第一種選擇是停止警報,第二種是從通知菜單中將其關閉。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.