如何使用推送通知发送图像?

时间:2019-05-14 07:05:28

标签: android firebase cordova firebase-cloud-messaging cordova-plugins

如何使用FCM发送带有图像的推送通知,我已经使用了以下内容,但仍然仅在通知中获得标题和文本。

我使用了基于Cordova的混合应用程序。如果有人有任何想法,请告诉我。

示例卷曲代码:

curl https://fcm.googleapis.com/fcm/send -X POST \
--header "Authorization: key=<AUT KEY>" \
--Header "Content-Type: application/json" \
 -d '
 {
   "to": "<to TOKEN>"
   "notification":{
     "title":"New Notification!",
     "body":"Test",
     "color":"#ff0000",
     "icon":"noti_icon",
     "img_url": "https://static.pexels.com/photos/4825/red-love-romantic-flowers.jpg",
     "image"  : "http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
    "avatar_url"  : "http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
    "url"  : "http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
    "image_url"  : "http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
    "largeIcon":"http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
   },
   "data" : {
      "img_url": "https://static.pexels.com/photos/4825/red-love-romantic-flowers.jpg",
      "image"  : "http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
      "avatar_url"  : "http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
      "url"  : "http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
      "image_url"  : "http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
      "message": "Firebase Push Message Using API",
      "largeIcon":"http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
      "main_picture":"http://cernyyachtdesign.com/wp-content/uploads/png-test.png",
    },
   "priority":1
 }'

Like this screenshot

谢谢。

1 个答案:

答案 0 :(得分:0)

最后两天后,我得到了解决方案,可以在cordova应用程序中显示所有类型的通知。

插件详细信息:https://github.com/phonegap/phonegap-plugin-push

如果要使用上述插件,请确保必须删除cordova-plugin-firebase,否则它将相互冲突。

有关更多详细信息,请检查上面的git链接,其中包含此插件的详细信息流程。我已经在android@8.0.0

上进行了测试