Adit Luhadia
Adit Luhadia

Reputation: 412

How to open a link when user clicks on Firebase notification in a Flutter App?

I am using Firebase in a Flutter app. To send notifications, I am using Firebase Messaging plugin. Whenever I send a notification using Firebase website, the notification just opens the app when user clicks on it. I want to send a notification which opens a URL instead of the app.

I don't know if this information is useful: while composing a notification on Firestore, I always put click_action as FLUTTER_NOTIFICATION_CLICK in "Custom data" section in Additional Options.

Upvotes: 1

Views: 4140

Answers (1)

Hamed Rahimvand
Hamed Rahimvand

Reputation: 630

You can use onLaunch() and onResume() methods to handle notification's opening action.

for more information of notification's reaction on different platforms please see below link: https://pub.dev/packages/firebase_messaging#receiving-messages

 _firebaseMessaging.configure(
       onMessage: (Map<String, dynamic> message) async {
         print("onMessage: $message");
       },
       onBackgroundMessage: myBackgroundMessageHandler,
       onLaunch: (Map<String, dynamic> message) async {
         print("onLaunch: $message");
       },
       onResume: (Map<String, dynamic> message) async {
         print("onResume: $message");
       },
     );

And you can use url_launcher to open URLs: https://pub.dev/packages/url_launcher

Upvotes: 3

Related Questions