react-native-push-notification icon indicating copy to clipboard operation
react-native-push-notification copied to clipboard

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

Open mcastillo86 opened this issue 2 years ago • 7 comments

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

<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>

mcastillo86 avatar Jan 09 '24 06:01 mcastillo86

Check if you've asked for permissions for notifications.

akshayhalasangi avatar Jan 09 '24 15:01 akshayhalasangi

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.

mcastillo86 avatar Jan 10 '24 14:01 mcastillo86

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

ericowhadi avatar Feb 22 '24 14:02 ericowhadi

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 avatar Feb 25 '24 07:02 mrazekrad

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

mrazekrad avatar Feb 26 '24 05:02 mrazekrad

Hey all folks here by spending over a day I have found a solution , FCM override function OnMessageRecieved will not call when app is killed , so you have to override Onhandleintent function inside your FCM . And from there you can add logic inside that function to show custom notification on the screen .🙂

chakshit89 avatar Aug 02 '24 21:08 chakshit89