-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[🐛] setBackgroundMessageHandler() only working when app loads - Android 14 #8088
Comments
I am also facing the same issue, Have you found any solution @wahas-mughal? |
me too |
same issue here please help |
getting the same issue |
Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?
Thank you for your contributions. |
Hey everyone, this is likely due to how Android 14+ changes how these things are handled. Try putting this into your AndroidManifest.xml.
This will allow background notifications to be handled. Then in the manifest adding the service:
This will allow Firebase Messaging to work in the background. Hope this helps! |
Hey @MichaelVerdon is this truly required for Android 14+ now? That seems like a major change but also totally plausible. I haven't tested much yet on Android 14 or 15. This seems like something we might need in the messaging package's AndroidManifest.xml. Might be tricky to coordinate with backwards-compatibility and permissions and foreground service types though - each of those items was difficult in Notifee repo |
Hey there @mikehardy Android 14+ made background services stricter meaning you have to explicitly get permission for it which I believe was to enhance user experience and stop meaningless stuff from happening. Do correct me if I have misinterpreted anything. |
setBackgroundMessageHandler() only receives the events when the app starts, after that it does not receive any event whether it's data only or notification enrich event on Android 14, below Android 14 it's working perfectly.
Project Files
I have the following code in index.js
Javascript
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import messaging from '@react-native-firebase/messaging';
messaging().setBackgroundMessageHandler(async remoteMessage => {
console.log('Notification for Background:', remoteMessage);
});
AppRegistry.registerComponent(appName, () => App);
Click To Expand
package.json
:{
"name": "trivialapp",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"startiPhone14ProMax": "npx react-native run-ios --udid A5B34590-AECD-4452-B840-F486D2F4344B",
"startiPhone11ProMax": "npx react-native run-ios --udid 54617BC6-D808-4ACE-8C9B-B18C6BB50E5F",
"start": "react-native start",
"lint": "eslint .",
"test": "jest"
},
"dependencies": {
"@notifee/react-native": "^9.1.2",
"@react-native-async-storage/async-storage": "^1.17.10",
"@react-native-community/push-notification-ios": "^1.11.0",
"@react-native-firebase/app": "^14.12.0",
"@react-native-firebase/messaging": "^14.12.0",
"@react-navigation/drawer": "^6.6.3",
"@react-navigation/material-top-tabs": "^6.2.3",
"@react-navigation/native": "^6.0.10",
"@react-navigation/native-stack": "^6.6.2",
"@reduxjs/toolkit": "^1.9.0",
"axios": "^0.27.2",
"deprecated-react-native-prop-types": "^4.2.3",
"lottie-react-native": "^5.1.3",
"moment": "^2.29.4",
"patch-package": "^8.0.0",
"react": "18.2.0",
"react-moment": "^1.1.2",
"react-native": "0.71.14",
"react-native-axios": "^0.17.1",
"react-native-code-push": "^7.1.0",
"react-native-date-picker": "^4.2.5",
"react-native-device-info": "^10.2.1",
"react-native-elements": "^3.4.2",
"react-native-fast-image": "^8.6.0",
"react-native-gesture-handler": "^2.9.0",
"react-native-linear-gradient": "^2.6.2",
"react-native-modal-dropdown": "^1.0.2",
"react-native-modern-datepicker": "^1.0.0-beta.91",
"react-native-pager-view": "6.2.3",
"react-native-paper": "^4.2.0",
"react-native-push-notification": "^8.1.1",
"react-native-reanimated": "^2.17.0",
"react-native-responsive-fontsize": "^0.5.1",
"react-native-responsive-screen": "^1.4.2",
"react-native-safe-area-context": "^4.3.1",
"react-native-screens": "^3.22.1",
"react-native-skeleton-content-nonexpo": "^1.0.13",
"react-native-snap-carousel": "^3.9.1",
"react-native-swiper": "^1.6.0",
"react-native-tab-view": "^3.1.1",
"react-native-uuid": "^2.0.1",
"react-native-vector-icons": "^10.0.1",
"react-native-webview": "^11.23.1",
"react-redux": "^8.0.5"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "7.20.0",
"@react-native-community/eslint-config": "3.2.0",
"@tsconfig/react-native": "^2.0.2",
"@types/jest": "^29.2.1",
"@types/react": "^18.0.24",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "29.2.1",
"eslint": "8.19.0",
"jest": "29.1.1",
"metro-react-native-babel-preset": "0.73.10",
"prettier": "^2.4.1",
"react-test-renderer": "18.2.0",
"typescript": "4.8.4"
},
"jest": {
"preset": "react-native"
}
}
# N/A
firebase.json
for react-native-firebase v6:# N/A
iOS
Click To Expand
ios/Podfile
:# N/A
AppDelegate.m
:// N/A
Android
Click To Expand
Have you converted to AndroidX?
android/gradle.settings
jetifier=true
for Android compatibility?jetifier
for react-native compatibility?android/build.gradle
:// N/A
android/app/build.gradle
:// N/A
android/settings.gradle
:// N/A
MainApplication.java
:// N/A
AndroidManifest.xml
:<!-- N/A -->
Environment
Click To Expand
react-native info
output:react-native-firebase
version you're using that has this issue:e.g. 5.4.3
Firebase
module(s) you're using that has the issue:e.g. Instance ID
TypeScript
?Y/N
&VERSION
React Native Firebase
andInvertase
on Twitter for updates on the library.The text was updated successfully, but these errors were encountered: