public void cancelAll() { NotificationManager notificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE); for (TrayNotification notification : NotificationContainer.getInstance()) { notificationManager.cancel(notification.getId()); } }
public void notify(TrayNotification notificationItem, Class activity) { // Get a reference to the NotificationManager: NotificationManager notificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE); // Instantiate the Notification: Notification notification = new Notification(getIcon(), notificationItem.getTickerText(), notificationItem.getWhen()); // Define the Notification's expanded message and Intent: Intent notificationIntent = new Intent(getContext(), activity); PendingIntent contentIntent = PendingIntent.getActivity(getContext(), 0, notificationIntent, 0); notification.setLatestEventInfo( getContext(), notificationItem.getTitle(), notificationItem.getMessage(), contentIntent); // Pass the Notification to the NotificationManager: notificationManager.notify(notificationItem.getId(), notification); // That's it. Your user has now been notified. }
public void cancel(TrayNotification notificationItem) { NotificationManager notificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(notificationItem.getId()); }