skip to Main Content

When application killed then notification click not working account to onSelectNotification and also big picture image notification not working when app in background.

flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: (action) {})

2

Answers


  1. Handle background messages by registering a onBackgroundMessage handler. When messages are received, an isolate is spawned (Android only, iOS/macOS does not require a separate isolate) allowing you to handle messages even when your application is not running. try this:

    @pragma('vm:entry-point')
    Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
      // If you're going to use other Firebase services in the background, such as Firestore,
      // make sure you call `initializeApp` before using other Firebase services.
      await Firebase.initializeApp();
    
      print("Handling a background message: ${message.messageId}");
    }
    
    void main() {
      FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
      runApp(MyApp());
    }
    

    follow full documentation here: https://firebase.google.com/docs/cloud-messaging/flutter/receive

    Login or Signup to reply.
  2. There is no such thing as "in the background" with mobile devices. Mobile devices run one foreground app. When you "put it in the background" it is closed and a screenshot is kept to make you think it’s "in the background". It’s not. It’s closed.

    So it does not work when it’s closed. That’s normal. Because the app isn’t running, it cannot execute code.

    The app has first to be started again. To find out, whether your app was started by tapping a notification, you can use this line in your start up code:

    final NotificationAppLaunchDetails notificationAppLaunchDetails =
    await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();
    

    Source: Documentation

    This way you can find out if your app was started from your notification and then act accordingly (for example by navigating to a different route depending on those details).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search