14

I'm using Google's Fcm to send notification to my Android client

I want to open specific screen with Deep Link url eg. example://my.app/products

Here is endpoint to send notification using REST api

https://fcm.googleapis.com/fcm/send
Content-Type: application/json
Authorization: key={SERVER_KEY}

{
 "to" : "{Firebase client token}",
 "collapse_key" : "type_a",
 "notification" : {
     "body" : "Body of Your Notification",
     "title": "Title of Your Notification"
     "click_action": "example://my.app/products"
 }
}

This request sends notification to my specified client, but does not open Deep Link, when clicking on push nothing happens

Is there a way to open Deep Link from Fcm Push ?

Mahdi Javaheri
  • 1,080
  • 13
  • 25

2 Answers2

11

This feature is not mentioned in Fcm documentation but i tried some sort of tests on my own and figured out the solution:

Instead of click_action we need to put link:

https://fcm.googleapis.com/fcm/send
Content-Type: application/json
Authorization: key={SERVER_KEY}

{
 "to" : "{Firebase client token}",
 "collapse_key" : "type_a",
 "notification" : {
     "body" : "Body of Your Notification",
     "title": "Title of Your Notification"
     "link": "example://my.app/products"  <<-- Here is the solution
 }
}
Mahdi Javaheri
  • 1,080
  • 13
  • 25
  • 2
    I've tried your solutions, but I got ``` { "error": { "code": 400, "message": "Invalid JSON payload received. Unknown name \"link\" at 'message.android.notification': Cannot find field.", "status": "INVALID_ARGUMENT", "details": [ .... ] } ] } } ``` – Dario Scoppelletti Dec 09 '20 at 19:17
  • @DarioScoppelletti what is your request data ? – Mahdi Javaheri Dec 16 '20 at 06:47
  • 1
    The request data is: { "notification" : { "body" : "Message Text", }, "android" : { "priority" : "NORMAL", "notification" : { "sound" : "default", "channel_id" : "channel_id", "link" : "app://www.myapp.app/path/path" } }, "token" : "device_token" } Thanks – Dario Scoppelletti Dec 17 '20 at 13:02
  • @DarioScoppelletti You should put "link" part in outer "notification" object, are you using legacy api `https://fcm.googleapis.com/fcm/send` ? – Mahdi Javaheri Dec 18 '20 at 16:09
  • I am using the latest API `POST https://fcm.googleapis.com/v1/{parent=projects/*}/messages:send`. However now I am using another way: FCM send an only data message and the App forward it as a local notification, thus Deep Linking of Navigation Component works. Thanks - Dario Scoppelletti – Dario Scoppelletti Dec 21 '20 at 14:49
  • @DarioScoppelletti so, Firebase itself doesn't support opening deeplinks when a user pressed on a notification, do I understand it right? – Oleg Yablokov Aug 11 '22 at 11:10
  • @OlegYablokov. Yes, I still use my solution from Dec 21, 2020. I don't know if anything has changed since then. – Dario Scoppelletti Aug 12 '22 at 15:17
  • @DarioScoppelletti this seems to be android specific. I have a react native app and I also need to embed the deep link in the firebase cloud message. How can I make it work for both iOS and android? – Victor Cui Aug 15 '22 at 17:56
  • @VictorCui Sorry, but I don't know React Native – Dario Scoppelletti Aug 17 '22 at 13:45
1

Note: if you actually want to open a page in your app when the user clicks on a notification, refer to this.

I post it as an answer because I tried to implement opening a page in my app and thought deep links would help but it is probably not the best solution.

Oleg Yablokov
  • 736
  • 8
  • 19