flutter_local_notifications icon indicating copy to clipboard operation
flutter_local_notifications copied to clipboard

onDidReceiveBackgroundNotificationResponse callback doesn't in background

Open koutja opened this issue 1 year ago • 8 comments

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

koutja avatar May 03 '24 08:05 koutja

Same to me, it seems to not work properly!

p3pp8 avatar May 06 '24 16:05 p3pp8

Same problem

dshevchenkoo avatar May 08 '24 13:05 dshevchenkoo

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
    }
  }

Adamteh avatar May 29 '24 08:05 Adamteh

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?

binhtran93 avatar Jun 07 '24 15:06 binhtran93

Same problem

mtiendat avatar Jun 07 '24 15:06 mtiendat

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

binhtran93 avatar Jun 07 '24 15:06 binhtran93

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

mtiendat avatar Jun 07 '24 15:06 mtiendat

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

MaikuB avatar Jun 10 '24 07:06 MaikuB

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 https://github.com/MaikuB/flutter_local_notifications/issues/2315#issuecomment-2136799521 solved the issue decribed here (for foreground notifications): https://github.com/MaikuB/flutter_local_notifications/issues/2390.

Anyone solved this somehow?

ced1check avatar Sep 16 '24 10:09 ced1check

Tried updating plugin from 16.1.0 to 17.2.2 as suggested in https://github.com/MaikuB/flutter_local_notifications/issues/2404, to no avail unfortunately. Did a flutter clean flutter pub get, made no difference!?

ced1check avatar Sep 17 '24 05:09 ced1check

@ced1check did you check my response that I made back in June that was above yours at https://github.com/MaikuB/flutter_local_notifications/issues/2315#issuecomment-2157489762? From what you've said, I suspect you may have a similar misunderstanding

MaikuB avatar Sep 19 '24 20:09 MaikuB

@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 https://github.com/MaikuB/flutter_local_notifications/issues/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).

ced1check avatar Sep 20 '24 04:09 ced1check

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 avatar Sep 20 '24 09:09 MaikuB