-
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
[🐛] 🔥 Not allowed to start service Intent ReactNativeFirebaseMessagingHeadlessService: app is in background uid #4604
Comments
I think it may be that no one uses the console to send notifications normally? Once all set up initially I think most people craft JSON and post it to the REST APIs via functions and some other sort of front-end. I'm just looking to explain the apparent documentation gap Can you explain where you saw the message
...was that via watching I would differ from your conclusion in that believe setting to high priority may be required to insure deliver, just not documented - or it may be documented in the upstream/official firebase docs |
The message can be found in the // class ReactNativeFirebaseMessagingReceiver
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "broadcast received for message");
if (ReactNativeFirebaseApp.getApplicationContext() == null) {
ReactNativeFirebaseApp.setApplicationContext(context.getApplicationContext());
}
RemoteMessage remoteMessage = new RemoteMessage(intent.getExtras());
ReactNativeFirebaseEventEmitter emitter = ReactNativeFirebaseEventEmitter.getSharedInstance();
// Add a RemoteMessage if the message contains a notification payload
if (remoteMessage.getNotification() != null) {
notifications.put(remoteMessage.getMessageId(), remoteMessage);
ReactNativeFirebaseMessagingStoreHelper.getInstance().getMessagingStore().storeFirebaseMessage(remoteMessage);
}
// |-> ---------------------
// App in Foreground
// ------------------------
if (SharedUtils.isAppInForeground(context)) {
emitter.sendEvent(ReactNativeFirebaseMessagingSerializer.remoteMessageToEvent(remoteMessage, false));
return;
}
// |-> ---------------------
// App in Background/Quit
// ------------------------
try {
Intent backgroundIntent = new Intent(context, ReactNativeFirebaseMessagingHeadlessService.class);
backgroundIntent.putExtra("message", remoteMessage);
ComponentName name = context.startService(backgroundIntent);
if (name != null) {
HeadlessJsTaskService.acquireWakeLockNow(context);
}
} catch (IllegalStateException ex) {
// By default, data only messages are "default" priority and cannot trigger Headless tasks
Log.e(
TAG,
"Background messages only work if the message priority is set to 'high'",
ex
);
}
} The method
I'm not sure what background messages are. I'm sending a regular push notification, not data-only notification. |
Unfortunately there is no such thing as a "regular push notification", all types of notification are "regular", none are "irregular" - to be precise you may say "cloud message with notification payload", "cloud message with data payload" or "cloud message with mixed payload". And to be most precise and avoid naming confusion, it is easiest to post the cloud messages via the REST API to the FCM system, and include the actual JSON you sent, so that we may troubleshoot with precision. rnfirebase.io are our official docs, but we are sometimes behind the actual official docs upstream: https://firebase.google.com/docs/cloud-messaging/android/receive I believe these restrictions are related to this: https://firebase.google.com/docs/cloud-messaging/android/receive#restricted which leads to https://firebase.google.com/docs/cloud-messaging/android/receive#restricted which leads to https://developer.android.com/topic/performance/power/power-details Basically, the Android platform has progressively tightened how and when things may happen in response to cloud messages, and without it being high priority it not okay for much to happen - even if it is high priority you may only send a few of these things to do It's very touchy getting this stuff to work, that is 100% true |
@mikehardy Thanks for a response. You're right, I should have been more precise. I send FCM messages with the optional payload (or not, makes no difference). My app is not restricted in terms of notification. I think the links you sent are suggesting that if the user puts the restriction on the app, the notification might be not delivered. In my case, the message is always delivered but the interaction with the message is not working (eg. function registered via |
Okay, delivery is good - note that the system restricts these things automatically - but if you still have standby bucket slots available then you get messages delivered - good Why is the interaction not working? Unsure, I believe you logged a separate issue that resolved to effectively the same thing. I can only recommend going into node_modules and directly inspecting all of the relevant code with tracing or printouts. I personally use a full-featured local notifications package to handle these things and I recommend to everyone they do the same - local notification interaction (that is: posting notifications, reacting to them) will always, always work better with a package that is doing that as it's intended purpose |
No worries @mikehardy . I closed the previous issue. Anyway, I think I found the issue. This interaction callback registered via |
react-native-push-notification should be able to handle these things, and may in fact (through swizzling / taking over the notification delegate) be the reason you don't see react-native-firebase notification handlers called Very interesting it works with the react-native upgrade 🤔 - I suppose that's at least a positive, better to be upgraded there as if I recall somewhere between 0.60 and 0.63.x there were quite a few changes required for android 10/11 and iOS14 |
I'm on 0.63.3 but still |
Hello, this error is happening to me, I am using only rnfirebase and when I get a push it does not open the app. |
I try with @react-native-firebase/messaging version 10.3.1 and now with i test on android console i have the error: |
@mezalejandro why would you attempt to troubleshoot on outdated software (possibly with fixes for whatever issue you have)? Don't do that! It has great potential to waste your time, and typically we don't spend any time looking at issues on non-current software
we are on 12.1.0 right now |
You are right, |
@mezalejandro - that was more of a warning to hopefully save you time, it was not really directed help. I have no idea what is going on there, sorry. There is not enough information here to reason about, and it's hijacking an old issue. I recommend producing an App.js we can drop in to the result of https://github.com/mikehardy/rnfbdemo/blob/master/make-demo.sh so we have a reproducible example https://stackoverflow.com/help/minimal-reproducible-example based on current versions, and if you can still reproduce it in a clean setting, then make a new issue and post the full error message from logcat so we may investigate |
Hi I am getting this issue in "Pre-launch" report from Play Store:
My package json versions are as follows:
And after searching around I found this issue on stackoverflow and according to one answer we need to start service base on the Android version which I found in the
Do someone has any idea that if I use the patch-package to replace this line with the following will it fix this issue?
I am going to do it anyways to check btw but wanted to see if someone can be a heads up as my previous app build is still in review. Thanks |
@yasirtrimulabs your versions are unsupportably old, and failure to work on modern mobile operating systems is the inevitable result.
If you keep your versions up to date here, things will continue working as new android/ios versions are released. The problems related to new operating system versions are handled in the new versions here, it is one of the primary drivers for new releases. |
@mikehardy thanks for the quick reply I know I have to upgrade but I am just worried that the new version will have breaking changes, can you please tell me if there will be any breaking changes for this one, because it can take some time to resolve these changes and I had to deliver the build ASAP IYKWIM 🙂 |
I've written an article on the same https://invertase.io/blog/react-native-firebase-versioning |
Thanks |
Issue
I implemented in my app
onNotificationOpenedApp
andgetInitialNotification
. However, both of these methods don't work as described in the documentation on Android. When the app is in the background, the notification comes, I tap on it, the app opens but the callback registered ononNotificationOpenedApp
is not called. The same is true for the app that is in quit state andgetInitialNotification
callback.After some debugging, I see that when the notification comes,
onReceive
method fromReactNativeFirebaseMessagingReceiver
class is called and the error is thrown when the service should be started:I see the description of this error: "Background messages only work if the message priority is set to 'high'"
To send notification, we use firebase console which I believe doesn't have an ability to set priority for a notification.
My questions are:
onNotificationOpenedApp
andgetInitialNotification
callbacks called only for messages with priorityhigh
?I believe the setting priority is not required as this is not documented anywhere.
Is there any other reason why this error can be thrown? Maybe I have some permissions not set up correctly. 🤔
Project Files
Javascript
Click To Expand
package.json
:firebase.json
for react-native-firebase v6: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
:android/app/build.gradle
:android/settings.gradle
:MainApplication.java
:AndroidManifest.xml
:Environment
Click To Expand
react-native info
output:react-native-firebase
version you're using that has this issue:@react-native-firebase/[email protected]
Firebase
module(s) you're using that has the issue:onNotificationOpenedApp
TypeScript
?Y
&3.5.3
React Native Firebase
andInvertase
on Twitter for updates on the library.The text was updated successfully, but these errors were encountered: