Flutter - Automatically run the application when notification received from FCM (without clicking it)

Viewed 4439

I'm developing a delivery app, when the client orders something i want the supplier app to open up on screen with 2 buttons to accept or decline the order.

its easy to do when the supplier clicks the notification (onLaunch and onResume configuration), but i want it to happen without their interaction.

Something like when someone calls you on whatsapp or FB messanger.

is this achievable ? couldnt find such a thing in flutter.

3 Answers

https://pub.dev/packages/flutter_local_notifications

      AndroidNotificationDetails(
                      'full screen channel id',
                      'full screen channel name',
                      'full screen channel description',
                      priority: Priority.high,
                      importance: Importance.high,
                      fullScreenIntent: true),

this will open app for android

Note: This old way for implementing the the FCM Notification,

As for the the Documentation, Notification come your app, either it is in foreground or background. But in these case of Background: A notification is delivered to the device's system tray and the data payload is delivered in the extras of the intent of your launcher Activity.

Case of Foreground: You can navigate to any screen. with help of

final FirebaseMessaging fcmMessaging = FirebaseMessaging();
 
fcmMessaging.configure(

onMessage: (Map<String, dynamic> message) async {
            print("onMessage: $message");
        },

onLaunch: (Map<String, dynamic> message) async {
            print("onLaunch: $message");
            // your code 
        },

onResume: (Map<String, dynamic> message) async {
            print("onResume: $message");
            
        },
);

New way : https://stackoverflow.com/a/73221621/5197656

Take a look at the firebase_messaging docs where it explains how to setup background messages on Optionally handle background messages

Related