habitoti
habitoti

Reputation: 239

Remove Firebase Notifications from tray (Android, Unity SDK)

I successfully implemented the Firebase Unity SDK for notifications (sent by a cloud function). My understanding of notifications is that it should not end up in the notification tray at all if the app is open and takes it (it has data and notification portion), however in fact all notifications pile up in the tray. I managed to provide a CollapseKey and according message tag to at least have just the latest one show up there, however as long as the app is in the foreground (also when device goes to sleep) there is actually no point in notifying via tray. So what I would like to do is to actively remove any notification on app start or recovery from pausing/sleeping. Is that somehow possible? I haven't found any API within the Unity SDK.

Thanks, habitoti

Upvotes: 0

Views: 753

Answers (1)

Patrick Martin
Patrick Martin

Reputation: 3131

It looks like this is an issue on Android proper as well, and there's already a good Stack Overflow post on it. If you're unable or uncomfortable with writing a native Android plugin (I actually create an Android messaging plugin in this article as an example), I think I have a pure Unity solution.

First, you will need to pull in the Mobile Notifications package (the documentation is for a preview, but it looks like 1.0.3 is stable).

Then you should be able to call CancellAllNotifications as listed here. It's a static function, so all the code you should need is:

AndroidNotificationCenter.CancellAllNotifications();

LMK if that works for you!

--Patrick

Upvotes: 2

Related Questions