单击 Fcm 通知时打开深层链接 url

Mah*_*eri 7 android deep-linking firebase-cloud-messaging

我正在使用 GoogleFcm向我的Android客户端发送通知

我想用 Deep Link url 打开特定的屏幕,例如。 example://my.app/products

这是使用 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"
 }
}
Run Code Online (Sandbox Code Playgroud)

此请求向我指定的客户端发送通知,但未打开深层链接,单击推送时什么也没有发生

有没有办法从 Fcm Push 打开 Deep Link?

Mah*_*eri 12

Fcm 文档中没有提到此功能,但我自己尝试了一些测试并找到了解决方案:

我们需要放置link而不是click_action

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
 }
}
Run Code Online (Sandbox Code Playgroud)

  • 我已经尝试过你的解决方案,但我得到了``` {“error”:{“code”:400,“message”:“收到无效的JSON负载。‘message.android.notification’处的未知名称\“link\” : 找不到字段。", "status": "INVALID_ARGUMENT", "details": [ .... ] } ] } } ``` (2认同)