且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

应用程序关闭时推送通知不起作用

更新时间:2023-02-27 09:20:24

最近我遇到了这个问题,我通过自动启动解决了这个问题

参考:https://docs.telerik.com/platform/knowledge-base/troubleshooting/troubleshooting-cannot-receive-push-notifications-on-android-when-the-app-is-closed

不仅仅适用于 Firebase

当应用关闭时,某些 Android 设备无法接收推送通知.应用可以在运行时接收推送通知,无论是在前台还是在后台.

原因

在这些设备上,默认情况下不允许大多数应用程序在后台醒来.这样应用程序就无法处理收到的未运行时推送通知.

目前,此行为仅在以下制造商的设备上识别:

  • 华为
  • 小米
  • 华硕

解决方案

您需要修改设备上的某些设置.

华为设备

打开设置 → 受保护的应用程序

将您的应用程序放入列表中

小米设备

在应用程序屏幕上点击安全应用程序选择权限 →自动启动 在列表中找到您的应用程序并启用自动启动"重新启动设备

华硕设备

按照此处所述找到自动启动管理器列出并启用允许"

编辑 2

从这里获取更多信息

https://github.com/firebase/quickstart-android/issues/41

I am working in react native project where I required to have push notification from server to be implemented in my app. I tried to use firebase as the notification provider. For that, I used react-native-firebase package. I tried this example link Its working fine when the app is running. But notification failed to come when the app is closed. So how can I achieve this

My target Android version is KitKat

Recently i face this problem i solve this issue by autostart

Ref : https://docs.telerik.com/platform/knowledge-base/troubleshooting/troubleshooting-cannot-receive-push-notifications-on-android-when-the-app-is-closed

Not For Only Firebase

some Android devices cannot receive push notifications when the app is closed. The app can receive push notifications when it is running, either in the foreground or in the background.

Cause

On these devices most of the apps are not permitted by default to be awaken in the background. This way the app cannot process the received push notification when it is not running.

Currently, this behavior is identified only on devices from the following manufacturers:

  • Huawei
  • Xiaomi
  • Asus

Solution

You need to modify certain settings on your device.

Huawei devices

Open Settings → Protected Apps

Place your application in the list

Xiaomi devices

On the app screen tap on the Security app Select Permissions → Autostart Locate your app in the list and enable "Autostart" Restart the device

Asus devices

Locate the Auto-start Manager as noted here Locate your app in the list and enable "Allow"

Edit 2

Get More Info From Here

https://github.com/firebase/quickstart-android/issues/41