Get all the remote notifications on application launch in Android

0

I need to collect all the remote notifications (received when the application was not running) from the android notification center on the application launch.

I have tried using the NotificationManager.getActiveNotifications method, but this gives the array of StatusBarNotification. There is a method getNotification() available on StatusBarNotification but this also does not have the remote notification content.

I have tried something like this,

 NotificationManager notificationManager = (NotificationManager) cordova.getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
StatusBarNotification[] notifications = notificationManager.getActiveNotifications();
for (int i = 0; i < notifications.length ; i++) {
    Notification notification = notifications[i].getNotification();
    Log.d("Tag","Notification String = " + notification.toString());
}

Output: Notification String = Notification(channel=fcm_fallback_notification_channel pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x10 color=0x00000000 vis=PRIVATE semFlags=0x0 semPriority=0 semMissedCount=0)

Please help me with your suggestions.

Many thanks!

android
android-notifications
asked on Stack Overflow Oct 19, 2020 by rahul.mahajan

1 Answer

1

If you want to get the notification data then please use

Bundle bundle = notification.extras

here bundle will have all the data received as payload. So if you want to get title then use bundle.getString("android.title");

answered on Stack Overflow Oct 22, 2020 by Ajay Choudhary

User contributions licensed under CC BY-SA 3.0