How to read received notifications in flutter
Asked Answered
S

2

6

I know the flutter_local_notifications_plugin allows an app to display notifications.

I want to access the data of notifications that is received, regardless of whether the app is running in the foreground, in the background, or not running.

Essentially the app needs to
- Add that notification to a persistent storage, and
- Depending on the notification, make a call to an API (eg an HTTP GET), and
- Depending on user preference settings, display a local notification

Note the question is not about the detail of implementing these three things as those would each be worthy of a whole article. But how to "receive" these events in each of the three possible app states, on both Android and iOS?

Broadly I expect some kind of broadcast receiver would need to be registered and a call-back needs to be created for when the event is triggered. I imagine this callbackmay want to be in a special Isolate perhaps since it can't depend on the app being in any particular state.

Spanish answered 23/7, 2019 at 6:31 Comment(0)
I
5

For Android devices, you can use the Notification package. For iOS I'm afraid there's no solution yet.

void onData(NotificationEvent event) => print(event.toString());
Instructor answered 28/12, 2019 at 1:42 Comment(0)
S
0

For iOS

When taking permission, give the announcement parameter to true.

FirebaseMessaging messaging = FirebaseMessaging.instance;
messaging.requestPermission(announcement: true);

For Android

Use Notification package.

Sukiyaki answered 20/9 at 13:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.