Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onDidReceiveBackgroundNotificationResponse callback doesn't in background #2315

Closed
koutja opened this issue May 3, 2024 · 13 comments
Closed

Comments

@koutja
Copy link

koutja commented May 3, 2024

Describe the bug

I ran the project from the example folder and I don't have notificationTapBackground called in the example onDidReceiveBackgroundNotificationResponse: notificationTapBackground

await flutterLocalNotificationsPlugin.initialize(
    initializationSettings,
    onDidReceiveNotificationResponse: (NotificationResponse notificationResponse) {
      notificationTapBackground(notificationResponse); // it works
    },
    onDidReceiveBackgroundNotificationResponse: notificationTapBackground,  // it doesn't work
  );

notificationTapBackground

@p3pp8
Copy link

p3pp8 commented May 6, 2024

Same to me, it seems to not work properly!

@dshevchenkoo
Copy link

Same problem

@Adamteh
Copy link

Adamteh commented May 29, 2024

You can use the getNotificationAppLaunchDetails method instead. It returns a NotificationAppLaunchDetails which contains didNotificationLaunchApp to check if the notification launched the app and the NotificationResponse.

  final appLaunchDetails =
      await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();

  if (appLaunchDetails != null && appLaunchDetails.didNotificationLaunchApp) {
    if (appLaunchDetails.notificationResponse != null) {
      //Your logic
    }
  }

@binhtran93
Copy link

Same problem, onDidReceiveBackgroundNotificationResponse did not get called when tapping on text action.
Tapping on text action which has showsUserInterface = false did not close the notification. Does anyone know a way to do it?

@mtiendat
Copy link

mtiendat commented Jun 7, 2024

Same problem

@binhtran93
Copy link

It turns out that it was my fault for not configuring the AndroidManifest file properly. The callback is getting called now

@mtiendat
Copy link

mtiendat commented Jun 7, 2024

Add <receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ActionBroadcastReceiver" /> to your AndroidManifest. it will be work

@MaikuB
Copy link
Owner

MaikuB commented Jun 10, 2024

The plugin is working as expected. I suspect the OP hasn't read the docs around the callback as the callback isn't about firing when the app is in the background. It's more on when the background isolate is used, especially for notification actions. Similarly the FCM callback has a callback that is invoked on a background isolate

@ced1check
Copy link

ced1check commented Sep 16, 2024

Turns out, I can't make onDidReceiveBackgroundNotificationResponse called or any of workaround offered here work when notification has been handled by OS (in background).

I check if didNotificationLaunchApp is true during app lifecycle resumed state change and it's false!

However this #2315 (comment) solved the issue decribed here (for foreground notifications): #2390.

Anyone solved this somehow?

@ced1check
Copy link

ced1check commented Sep 17, 2024

Tried updating plugin from 16.1.0 to 17.2.2 as suggested in #2404, to no avail unfortunately. Did a flutter clean flutter pub get, made no difference!?

@MaikuB
Copy link
Owner

MaikuB commented Sep 19, 2024

@ced1check did you check my response that I made back in June that was above yours at #2315 (comment)? From what you've said, I suspect you may have a similar misunderstanding

@ced1check
Copy link

ced1check commented Sep 20, 2024

@ced1check did you check my response that I made back in June that was above yours at #2315 (comment)? From what you've said, I suspect you may have a similar misunderstanding

My bad, I actually didn't understand your comment at all and didn't read documentation.

Reading the doc now, I understand it's purpose is to receive (pre-registered on iOS) actions from notifications, nothing more, nothing else. It won't get tap notification, farless its payload if any, and certainly not from a GCM notification.

So why is this bug still open, if it's not a bug?

Anyhow, I was originally looking for a solution for #2390, and found it here as a workaround only.

By the name of OP's title I assumed (wrongly) that this method was used for tap on notifications received while in background (from GCM in my scenario).

@MaikuB
Copy link
Owner

MaikuB commented Sep 20, 2024

So why is this bug still open, if it's not a bug?

Fair question and it's a combination of not having gotten around to do so and in case others in the community were going to provide more complete details e.g. a link to a repo hosting a minimal app that can reproduce the issue. I will do so now to avoid further confusion.

Note for others here that see this GitHub issue that the callback is only for notification actions that the app needs to respond to when it's not running. The "background" portion of the callback's name (onDidReceiveBackgroundNotificationResponse) isn't to do with if the app is in the background

@MaikuB MaikuB closed this as completed Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants