我有一个由Notification
触发的AlarmManager
。这是我的代码:
notification = new NotificationCompat.Builder(getActivity());
AlarmManager alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
Intent notificationIntent = new Intent("android.media.action.DISPLAY_NOTIFICATION");
notificationIntent.addCategory("android.intent.category.DEFAULT");
PendingIntent broadcast = PendingIntent.getBroadcast(getContext(), 5000, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.setExact(AlarmManager.RTC_WAKEUP, 10000, broadcast);
alarmManager.cancel(broadcast);
// here am trying to cancel the notification with PendingIntent but its not working
编辑:
通过工作我的意思是它不取消通知应该
答案 0 :(得分:1)
使用
PendingIntent.getBroadcast(getContext(), 5000, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT).cancel();
而不是alarmManager.cancel(broadcast)