android - 图片未显示在推送通知中

标签 android firebase firebase-cloud-messaging

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

{
    "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用于在推送通知中包含图像的键值对。我的预期输出是:

enter image description here

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

enter image description here

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

最佳答案

我发现了问题在于激进的电池保护程序 .例如,小米和三星(尤其是 Android 11)手机将限制 FCM 进行后台联网(获取图像),因此图像将丢失。这只会在手机处于深度 sleep 时发生。如果不是(并且您的应用程序已关闭或在后台),则将显示图像。如果应用程序在前台,onMessageReceived()将被调用,无论如何您都需要手动获取图像,并且不受电话限制。
可悲的是,我没有找到任何解决方法,除了用户手动禁用您的应用程序的电池节省:/
enter image description here

关于android - 图片未显示在推送通知中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57725879/

相关文章:

android - 如何在当前 Activity 后面启动一个 Activity ?

android - Xamarin Android YouTube API-获取视频元数据

android - 执行 Android 项目时出错 "Activity class does not exist."

android - 动态启用/禁用隐藏/取消隐藏 Android ActionBar 操作图标

firebase - 获取 firebase/firestore SERVERTIME 并转换为日期(月和日)

firebase - 如何使用 Java 中的 FCM 将带有自定义图像的推送通知发送到 Web 应用程序

android - Firebase Android 默认设置和用户隐私

firebase - 有没有办法使用 "emailVerified"auth REST API'' 从我的 firebase auth 用户获取 ''?

android - 如果用户拥有多个设备,如何在我的服务器上存储 firebase token

javascript - 推送通知 Codelab 未捕获语法错误 : Unexpected identifier in curl request