zo0r / react-native-push-notification

React Native Local and Remote Notifications
MIT License
6.73k stars 2.05k forks source link

Android - Push notifications not received when app is closed (Killed/Terminated/etc) #2401

Open mcastillo86 opened 5 months ago

mcastillo86 commented 5 months ago

Question

Hello,

I've been using this package for quite a while but we've just noticed the our app is receiving foreground and background notifications but none is received when the app is closed. Below you can find my RN and this library versions, as well as some part of my android manifest file. Am I missing something?

package.json

"react-native": "~0.63.5", "react-native-push-notification": "8.1.1",

Android manifest

<meta-data android:name="com.dieam.reactnativepushnotification.default_notification_channel_id" android:value="channel-default" /> <meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name" android:value="Notificaciones" /> <meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground" android:value="true" /> <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/ic_stat_tlc" /> <meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="channel-default" /> <meta-data android:name="com.dieam.reactnativepushnotification.notification_color" android:resource="@color/white" />

<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" />
<receiver
  android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
<receiver
  android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver"
  android:exported="false">
  <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
    <action android:name="android.intent.action.QUICKBOOT_POWERON" />
    <action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
  </intent-filter>
</receiver>

<service
  android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
  android:exported="false">
  <intent-filter>
    <action android:name="com.google.firebase.MESSAGING_EVENT" />
  </intent-filter>
</service>
akshayhalasangi commented 5 months ago

Check if you've asked for permissions for notifications.

mcastillo86 commented 5 months ago

Thanks @akshayhalasangi but I have double checked that part, still nothing. Due to my version of react-native I followed this these steps. The app receives notifications when in background or foreground but not when it is closed.

ericowhadi commented 4 months ago

do you do PushNotification.configure in App.js or index.js?

mrazekrad commented 4 months ago

The same problem. PushNotification.configure is in index.js. Working on Android less then 13. Push notifications work when the app is in the foreground. Once it's off or in the background and a notification comes in, it kills the app.

Set environment according to https://dev.to/gautham495/asking-notification-permission-in-android-13-for-a-react-native-application-35n2

mrazekrad commented 4 months ago

this solved my problem:

app/src/main/AndroidManifest.xml add =>

android/app/build.gradle add=> implementation platform('com.google.firebase:firebase-bom:29.0.1')

android/build.gradle

buildToolsVersion = "30.0.2" minSdkVersion = 23 compileSdkVersion = 33 targetSdkVersion = 33

And check permissions: export const checkAndroidPermissionPostNotifications = async () => { if (Platform.OS === "android" && Platform.Version >= 33) { try { // @ts-ignore - to be fixed after upgrade to RN 0.7+ const result = await PermissionsAndroid.check("android.permission.POST_NOTIFICATIONS"); //Permission is undefined, asking for it. if (result === undefined) { // @ts-ignore - to be fixed after upgrade to RN 0.7+ await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS); } } catch (error) {} } };

good luck to everyone! Radek