我正在使用下面的通知负载并使用 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 :/
这篇关于图片未显示在推送通知中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!