-1

I have a Notification that is triggered by an AlarmManager. This is my code:

    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 

EDIT:

by working i meant its not canceling the notification at is supposed to

remy boys
  • 2,928
  • 5
  • 36
  • 65

1 Answers1

1

use

PendingIntent.getBroadcast(getContext(), 5000, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT).cancel();

instead of alarmManager.cancel(broadcast)

thanks to these post Cancelling a PendingIntent

Community
  • 1
  • 1
Skrillex
  • 22
  • 5