图片未显示在推送通知中

Image not showing in push notification(图片未显示在推送通知中)
本文介绍了图片未显示在推送通知中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的通知负载并使用 Postman 向 Android 设备发送推送通知:

I am using the notification payload below and use Postman to send a push notifications to Android devices:

{
    "to" : "/topics/xxxx" ,
    "data" : {
        "url" : "https://res.cloudinary.com/demo/image/upload/w_200/lady.jpg",
        "dl" : ""
    },
    "notification" : {
        "title" : "This is a sample notification from general2",
        "body" : "Rich notification testing (body)",
        "image": "https://res.cloudinary.com/demo/image/upload/w_200/lady.jpg"
    }

}

我已使用 image 键值对在推送通知中包含图像.我的预期输出是:

I have used the image key value pair to include an image in the push notification. My expected output is:

但这就是它在手机中显示的内容:

But this is what it is showing in the phone:

如您所见,图像没有出现.可能是什么问题?

As you can see, the image is not appearing. What might be the problem?

推荐答案

我发现问题在于激进的节电模式.例如,小米和三星(尤其是 Android 11)手机将限制 FCM 进行后台联网(获取图像),因此图像将丢失.这只会在手机处于深度睡眠时发生.如果不是(并且您的应用程序已关闭或在后台),则将显示图像.如果应用在前台,会调用onMessageReceived(),反正需要手动获取图片,不受手机限制.

I found out the problem is in aggressive battery savers. For example, Xiaomi and Samsung (Android 11 especially) phones will restrict FCM to do background networking (to fetch the image), thus, the image will be missing. This will only happen when phone is in deep sleep. If it's not (and your app is closed or in background), the image will be showing. If the app is in foreground, onMessageReceived() will be called and you need to fetch the image manually anyways and it will not be restricted by phone.

遗憾的是,除了用户手动为您的应用禁用节电功能之外,我没有找到任何解决方法:/

Sadly, I didn't find any workaround around this, except users manually disabling battery saving for your app :/

这篇关于图片未显示在推送通知中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)