0

I search everywhere and couldn't find a good answer.

I'm using AlarmManager and BroadcastReceiver to send notifications at a certain time.

Below are a few lines of what I'm doing.

AlarmManager alarmManager = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE); Calendar alarmStartTime = GregorianCalendar.getInstance(); alarmManager.set(AlarmManager.RTC_WAKEUP, alarmStartTime.getTimeInMillis(), PendingIntent.getBroadcast(ctx, Integer.parseInt(alertID), alertIntent, PendingIntent.FLAG_UPDATE_CURRENT));

Everything works fine and I receive all the notification in the status bar. No worries about that.

My problem is: How can I cancel a certain notification before showing in status bar?

notificationManager.cancel(alertID); will only remove the notification after is shown in the status bar.

So what is the best way to "prevent" a notification from showing to the user?

Thank you in advance!

sfirc
  • 239
  • 4
  • 12
  • I don't understand your question. What do you mean by "prevent a notification from showing to the user"? If you don't want a notification, just don't call `NotificationManager.notify()`. – David Wasser Jun 22 '17 at 17:41
  • I wanted to stop a notification from being shown in status bar. I'm using AlarmManager and BroadcastReceiver. `NotificationManager.notify()` is used in a class that inherits BroadcastReceiver. In the meantime I found the solution to my problem: https://stackoverflow.com/questions/4963271/android-alarmmanager-problem-with-setting-resetting-an-alarm – sfirc Jun 23 '17 at 00:52

0 Answers0