仅在Android 11上,当应用程序在后台且关闭屏幕时,10 - 30分钟内不会收到高优先级推送消息。
这是在运行安卓11的Pixel 4XL上展示的。常规电池优化已关闭。应用程序特定的电池优化也已关闭。该设备已连接到WiFi网络。在4G连接上也显示出同样的行为。
根据我对文档的理解,高优先级fcm消息应该立即交付,并且不限于打瞌睡周期。
即使是打瞌睡,这种行为在关闭屏幕后的3分钟内仍然很明显,这不足以让深度打瞌睡激活。
当设备插入时,fcm消息工作正常。
如何让我的应用程序及时接收推送消息?
未提供负载的通知节点。只有数据。优先级设置为高。
发布于 2021-10-25 13:54:43
我在Android11上也遇到过同样的问题,特别是在Moto G6 & G8上。因为FCM是我们应用程序的主干,所以我想出了这个
class YourFCMServiceClass : FirebaseMessagingService(){
override fun onMessageReceived(remoteMessage: RemoteMessage) {
//Your handler Code
}
override fun onCreate() {
super.onCreate()
if (Build.VERSION.SDK_INT >= 26) {
val CHANNEL_ID = "your_channel_id"
val channel = NotificationChannel(
CHANNEL_ID,
"channel_name",
NotificationManager.IMPORTANCE_NONE
)
(getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).createNotificationChannel(
channel
)
val notification: Notification = NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("")
.setContentText("").build()
startForeground(1, notification)
}
}
}然后以foreground service身份手动启动FCM服务。
并为device reboot implement一个BroadcastReceiver,然后再次以foreground service身份手动启动该服务
class BootReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, p1: Intent?) {
conetxt.startForegroundService(Intent(context, YourFCMServiceClass::class.java))
}
}这对我来说很好。
https://stackoverflow.com/questions/64476235
复制相似问题