【问题标题】:Clickable image using firebase push notification使用 Firebase 推送通知的可点击图像
【发布时间】:2017-12-24 18:38:11
【问题描述】:

是否可以使用 firebase 推送通知通过通知发送可点击的图像,如果可以,我应该从哪里开始学习如何做?

【问题讨论】:

  • 你能详细说明这个问题吗?通过推送通知发送可点击图像是什么意思?你的意思是,推送通知将发送一个图片的链接(可能来自亚马逊网络服务?)以及一个相应的链接,该链接将由你的应用程序加载?
  • 我的意思是当用户收到通知时,他可以点击它,它会将他带到一个特定的链接。

标签: android firebase push-notification firebase-cloud-messaging


【解决方案1】:

是的,你可以。在 fcm 上有两个部分的推动。 1)通知 2)数据。 通知部分完全由谷歌管理。所以你必须使用数据部分。在数据部分发送一个 base64 图像字符串并在应用程序中将其解码为图像。见下文

if (remoteMessage.getData().size() > 0) {
            Log.d(TAG, "Message data payload: " + remoteMessage.getData());
Jsonobject obj=new JsonObject(remoteMessage.getData());
String image=obj.getString(“image_base64_string”);
//which you have to send from your backend or firebase console using this key
//then decode this image to bitmap and setimage to the imageview
        }

        // Check if message contains a notification payload.
        if (remoteMessage.getNotification() != null) {
            Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
        }

【讨论】:

  • 所以我必须在android studio项目中添加一个特定的代码才能让它工作?或者我只能使用我已经为普通文本推送通知进行的 google-services.json 设置来做到这一点?
  • 我应该把这段代码放在 MyFirebaseMessagingService.java 中吗?
  • yeap.in 消息服务类
  • 我遇到了很多错误,例如:错误:(248, 5) 错误:类型的非法开始,错误:(248, 30) 错误:预期 ,错误:(251, 36 ) 错误:非法字符:'\u201c',错误:(251, 56) 错误:非法字符:'\u201d'。
【解决方案2】:

是的,您可以在通知负载中发送 "click_action" => "http://google.com",以便在通知上引导 click_action 以及在用户点击收到的通知后您想要重定向的任何位置

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多