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 :/
这篇关于图片未显示在推送通知中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:图片未显示在推送通知中
基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
