Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mcastillo86 opened this issue Jan 9, 2024 · 7 comments

Comments

@mcastillo86
Copy link

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>
@akshayhalasangi
Copy link

Check if you've asked for permissions for notifications.

@mcastillo86
Copy link
Author

mcastillo86 commented Jan 10, 2024

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

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

@mrazekrad
Copy link

mrazekrad commented Feb 25, 2024

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

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

@chakshit89
Copy link

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

@QuocTuanIT87
Copy link

When the app is closed, receiving notifications will be delayed. It can be 3 to 5 minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants