0
我想通知我取消它自己的重複報警。但是,我不知道如何在創建之前傳遞pendingIntent(稍後取消它)。Android:通知取消它重複報警
報警設置在這裏:
public class Schedule extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "");
wakeLock.acquire();
//next is notification code. //
...
//create intent.
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context,
NOTIFY_ID, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
...
////
wakeLock.release();
}
public void setAlarm(Context context) {
...
Intent intent = new Intent(context, Schedule.class);
intent.putExtra("DELAY", delay);
intent.putExtra("NOTIFICATION_ID", id);
intent.putExtra("TITLE_TEXT", titleText);
intent.putExtra("BIG_TEXT", bigText);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1000 * 60 * delay, 1000 * 60 * delay, pendingIntent);
}
}
關鍵的問題是,我想取消通知單擊(onRecieve方法意圖)的重複報警,但如果取消報警需要的PendingIntent,該通知的一部分。任何方式來欺騙系統?
你好再次:)我看到了這個答案已經在這裏(當然,我試圖谷歌它之前問)。但問題是,方法cancel()需要在通知傳遞給它之後創建的pendingIntent。或者我可以簡單地創建具有相同ID的pendingIntent以便能夠取消它?如果是這樣,這是奇妙的。我會盡快嘗試,非常感謝你:) – Cakeee
這是行不通的:(我按照你說的做了,並且通知在點擊後繼續顯示。 – Cakeee
確保你使用相同的通知ID取消通知。你是否想刪除通過面板通知時點擊通知? – FAT