Push notification not working when application is

2019-08-05 06:00发布

问题:

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

回答1:

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



回答2:

Hi @Anuj there are two types of notification in firebase, notification and data payload . If you send as Notification it will work only when app is in foreground , ask backend team to send notification as data payload you have to set notification payload as null Check Here