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 is never called at Android #2148

Closed
holailusoria opened this issue Nov 7, 2023 · 3 comments
Closed

Comments

@holailusoria
Copy link

onDidReceiveBackgroundNotificationResponse is never called at Android.

To Reproduce

  1. Initialize flutter local notification plugin.
  2. Move the application to the background.
  3. Send push notification
  4. Tap on push notification.
  5. Logic in onDidReceiveBackgroundNotificationResponse(method as argument must have an annotation @pragma('vm:entry-point')) wasn't called.

Expected behavior
In step 5 described above method onDidReveiveBackgroundNotificationResponse has been called.

Sample code to reproduce the problem

final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
    FlutterLocalNotificationsPlugin();

@pragma('vm:entry-point')
void notificationTapBackground(NotificationResponse notificationResponse) {
  // ignore: avoid_print
  print('notification(${notificationResponse.id}) action tapped: '
      '${notificationResponse.actionId} with'
      ' payload: ${notificationResponse.payload}');
  if (notificationResponse.input?.isNotEmpty ?? false) {
    // ignore: avoid_print
    print(
        'notification action tapped with input: ${notificationResponse.input}');
  }
}

class test{
static initializePlugin() {
    try {
      final DarwinInitializationSettings initializationSettingsIOS =
          DarwinInitializationSettings(
              requestAlertPermission: true,
              requestBadgePermission: true,
              requestSoundPermission: true,
              onDidReceiveLocalNotification:
                  (int id, String? title, String? body, String? payload) async {
                // ignore: avoid_print
                print(
                    'Notification was receive: $title\nBody: $body\nPayload: $payload');
              });

      const AndroidInitializationSettings initializationSettingsAndroid =
          AndroidInitializationSettings('app_icon');

      final InitializationSettings initializationSettings =
          InitializationSettings(
        iOS: initializationSettingsIOS,
        android: initializationSettingsAndroid,
      );
      
      flutterLocalNotificationsPlugin.initialize(
          initializationSettings,
          onDidReceiveNotificationResponse: onDidReceiveNotificationResponse,
          onDidReceiveBackgroundNotificationResponse: notificationTapBackground,
        );
        catch (ex) {
      // ignore: avoid_print
      print('EXCEPTION: $ex');
    }
  }
}
@eakarpov
Copy link

I also cannot solve this problem, onDidReceiveBackgroundNotificationResponse is not triggered when notification is tapped

@baekjungkim
Copy link

I'm having the same problem.
Has this been resolved problem?

@MaikuB
Copy link
Owner

MaikuB commented Dec 4, 2023

This is expected behaviour, this callback is for notification actions and it's documented how you should deal with when a notification is tapped. Closing as it's a duplicate of #2134

@MaikuB MaikuB closed this as completed Dec 4, 2023
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

4 participants