1

I have a Flutter application (Android and iOS) which can handle Android Deep Links & App Links, and iOS Custom URL Schemes & Universal Links.

So the URLs...

company://service/items/{item-id}
https://service.company.com/items/{item-id}

... both open the "Item Detail" page for {item-id}, as expected and desired.

A backend server for this application sends FCM push notifications, which tell the user when a change has occurred for {item-id}.

Right now, clicking the push notifications just launches the main page of the app.

I am wondering if it is possible to construct the FCM message in such a way that... it tells the device to open the URL in the default system web browser, which would trigger the existing deep linking functionality I have in place?

I am thinking this would most likely be possible, since I would guess this would be a useful use-case for marketing materials, or actions which need to be completed on a website instead of within the app?

But at the same time, I could imagine that maybe it is not possible to triggering handling of a push notification from another app, than the FCM message receiver?

My rationale behind trying to handle this at the server/FCM broadcast stage, is because I want re-use the existing functional deep linking functionality if possible, with as little changes as possible in the common flutter layer, and avoiding native code as much as possible.

What I'm trying for Android:

{
  "notification": {
    "title": "Stackoverflow title", 
    "body": "Click on it to see what happens!",
    "click_action": "android.intent.action.VIEW",
    "data": "https://service.company.com/items/{item-id}"
  }, 
  "data": {
    "open_url": "https://service.company.com/items/{item-id}"
  },
  "android": {
    "notification": {
      "click_action": "android.intent.action.VIEW",
      "data": "https://service.company.com/items/{item-id}"
    }
  },
  "to": "..."
}

... but no luck.

Am I missing something? Or barking up the wrong tree?

Any and all advice and suggestions welcomed :-)

Cillian Myles
  • 696
  • 8
  • 16
  • Well you are right. But I thought of a workaround, We can already define routes on the OnLaunch, OnResume, OnBackground events. and navigate to the place according to the provided data. – Krish Bhanushali Oct 23 '20 at 18:24
  • Thanks for the info. I have tried this but no luck getting these callbacks to work on notification click. Will double check everything and see if I can't get them to work! Thanks – Cillian Myles Oct 25 '20 at 18:23
  • Did you tried ? – Krish Bhanushali Oct 27 '20 at 10:08
  • When I changed the format of my FCM message, I was able to trigger onResume and onLaunch. Changed format according to https://stackoverflow.com/a/56648598/5096103. Thanks for your advice @KrishBhanushali! – Cillian Myles Oct 27 '20 at 18:06
  • Welcome! well this was indeed a workaround I hope we find a better solution to this as then that would enable us to deeplink through the notifications. – Krish Bhanushali Oct 28 '20 at 06:54

1 Answers1

2

So I could not find a way to do what I wanted. I could, however, handle the notification click event directly in flutter like so:

  _fcm.configure(
    onMessage: (Map<String, dynamic> message) async => _showMessageHandler,
    onLaunch: (Map<String, dynamic> message) async => _openMessageHandler,
    onResume: (Map<String, dynamic> message) async => _openMessageHandler,
  );

As long as I sent the notification in the correct way - something like the following:

{
  "notification": {
    "title": "Title", 
    "body": "Body"
  },
  "priority": "high",
  "data": {
    "click_action": "FLUTTER_NOTIFICATION_CLICK",
    "open_url": "https://service.company.com/items/{item-id}"
  },
  "to": "..."
}
Cillian Myles
  • 696
  • 8
  • 16