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: onBackgroundEvent not fired when quick action is pressed #404
Comments
Hi, it sounds like there's an issue with |
Hi @helenaford, and thank your for your response! /**
* @format
*/
import messaging from '@react-native-firebase/messaging';
import { AppRegistry } from 'react-native';
import notifee from '@notifee/react-native';
import App from './App';
import { name as appName } from './app.json';
import firebaseNotificationHandler from './app/utils/firebaseNotificationHandler';
// Fired when the notification get displayed but not when an action get pressed!
notifee.onBackgroundEvent(async ({ type, detail }) => {
const { notification, pressAction } = detail;
if (type === EventType.ACTION_PRESS) {
if (pressAction.id === NOTIFICATION_ACTIONS_ID.acceptIncomingCall || type === EventType.PRESS) {
// accept call This is works because I set launchActivity: 'default'
incomingCallNotifications.handleAcceptCall(notification);
} else {
incomingCallNotifications.handleRejectCall(notification);
// handleRejectCall function
axios
.get(`${API_URL}/....`, {
headers: {
Authorization: accessToken,
},
})
.catch((err) => {});
}
}
});
// display notification when app is in foreground
messaging().onMessage(firebaseNotificationHandler.onMessageReceived);
// display notification when app is in background
messaging().setBackgroundMessageHandler(firebaseNotificationHandler.onMessageReceived);
AppRegistry.registerComponent(appName, () => App); I'm thinking |
I downgrade from onBackgroundEvent from the examplenotifee.onBackgroundEvent(async ({ type, detail }) => {
const { notification, pressAction } = detail;
console.log(`[onBackgroundEvent] notification id: ${notification?.id}, event type: ${EventType[type]}, press action: ${pressAction?.id}`);
// Check if the user pressed the "Mark as read" action
if (type === EventType.ACTION_PRESS && pressAction?.id === NOTIFICATION_ACTIONS_ID.cancelIncomingCall) {
console.log('[onBackgroundEvent] ACTION_PRESS: cancelIncomingCall');
// Remove the notification
if (notification?.id) {
await notifee.cancelNotification(notification?.id);
}
} else if (type === EventType.ACTION_PRESS && pressAction?.id === NOTIFICATION_ACTIONS_ID.acceptIncomingCall) {
console.log('[onBackgroundEvent] ACTION_PRESS: acceptIncomingCall');
// Remove the notification
if (notification?.id) {
await notifee.cancelNotification(notification?.id);
}
}
}); @notifee/react-native@4.0.1 Logs ✅ LOG [onBackgroundEvent] notification id: 0UCHEweojRsL, event type: DELIVERED, press action: undefined
LOG [onBackgroundEvent] notification id: 0UCHEweojRsL, event type: ACTION_PRESS, press action: cancelIncomingCal @notifee/react-native@5.2.1 Logs ❌ LOG [onBackgroundEvent] notification id: 0UCHEweojRsL, event type: DELIVERED, press action: undefined When an action get pressed onBackgroundEvent never get called |
🤔 hmm - what's the execution environment here? I don't see that specified (android vs ios) Our releases are usually pretty small so even though the range is large, the actual number of functional (non-test, non-docs) commits is pretty small: @notifee/react-native@4.0.1...@notifee/react-native@5.2.1 Total release count is 8 so if you attempted to bisect which release starts to fail it would probably take just 3 attempts before you located the precise commit and we'd have the bug on the dissection table 🔬 |
Hi, @mikehardy, first thank you for your time! Android environment
IOS environment
React native
I hope that can help |
It stops working from I don't want to downgrade, I remember there is a reason upgrading to v 5+ in |
That's great though! Really tight range of commits! Only 3 1- 50aa11e - going to say it's not that, it's only a model change, and java specific 2- f5da722 - maybe this one? But it is java only, and you did not differentiate on the failure, you indicated it was android and ios? Not sure how this could affect iOS as well 3- ed22c8f - massive change, but is also java only If the result of 4.0.1 working and 4.1.0 not working is to be believed, I'm confused how it could manifest on iOS. Can you confirm that this happens on both android and ios? If it is on both then there is something really subtle going on and will need some thinking. If it's actually android only then we pick apart the specific commits and find it |
@mikehardy it's an I tried intalling specific commit like this : Should I downgrade! |
Excellent! That means our methodology is correct - or at least it seems to be - you saying it is android only means we do seem to be testing what I think we're testing since it's android only changes in the version change that started the problem Excellent again if you are willing to install from a commit hash. I think the only step missing is to build the typescript source after install, calling this:
When I've done this for notifee before I've put this in a package.json::postinstall script: |
oh, I think it needs tsc etc, so you probably have to do |
We are also facing the same issue. |
@hussainimp indeed, it is almost undoubtedly this commit ed22c8f - just not sure exactly what yet - we can use all the help we can get with regard to isolating the specific issue and ideally 🙏 🙏 seeing a PR from someone affected - I can collaborate with anyone to get a fix released but this is not a personal use case of mine so it's not personally urgent and I won't have time to personally fix it at the moment, it will end up on the general work pile and might sit otherwise |
I tried yesterday installing one of three commits but not luck, I think I have some conflict with tsc version - I will give it another try because I really need this to work. |
I have the same problem. Only android is affected (testing on Pixel 5, Android 12). It works with the local test build, but not with the release build. In February I upgraded from So Somehow I can't get On the emulator i can install As it is not working for me even prior to
My app is solely for the purpose of receiving notifications which open web links, so this issue is completely breaking my app. :( |
I fixed the emulator and tested some more. With Android 11, @amjadbouhouch can you confirm that the release version is working for you on Android 12? Or how did you test it? I feel like this is broken for Android 12 in all notifee versions. @helenaford is ed22c8f supposed to fix this issue or something else? Are there now some restrictions with Android 12 that prohibit the following: My code in
|
Hi @fabyeah, unfortunately it's not working. build.gradle
gradle version
package.json"@notifee/react-native": "^5.2.2",
"react-native": "0.67.4", index.js/**
* @format
*/
import messaging from '@react-native-firebase/messaging';
import { AppRegistry } from 'react-native';
import App from './App';
import { name as appName } from './app.json';
import firebaseNotificationHandler from './app/utils/firebaseNotificationHandler';
// firebase
messaging().onMessage(firebaseNotificationHandler.onMessageReceived);
messaging().setBackgroundMessageHandler(firebaseNotificationHandler.onMessageReceived);
// notifee, same function as OnForegroundEvent
notifee.onBackgroundEvent(async (props) => firebaseNotificationHandler.handleOnForegroundEvent(props));
AppRegistry.registerComponent(appName, () => App); functions: // on foreground notification pressed;
handleOnForegroundEvent({ type, detail: { notification, pressAction } }: any) {
const notificationData = JSON.parse(notification.data.notification);
if (type === EventType.ACTION_PRESS && pressAction?.id === NOTIFICATION_ACTIONS_ID.acceptIncomingCall) {
return incomingCallNotifications.handleAcceptCall(notificationData);
}
if (type === EventType.ACTION_PRESS && pressAction?.id === NOTIFICATION_ACTIONS_ID.cancelIncomingCall) {
return incomingCallNotifications.handleRejectCall(notificationData);
}
if (type !== EventType.PRESS) {
return Promise.resolve();
}
return firebaseNotificationHandler.handleInitialNotification(notificationData);
},
async handleRejectCall(notification: IIcomingCallNotification) {
const { conversationId, notificationId } = notification;
const accessToken = await load('accessToken');
axios
.get(..............)
if (notificationId) {
await notifee.cancelNotification(notificationId);
}
}
async makeIncomingCallNotification(title: string, body: string, user: any, notification?: any) {
const callChannelId = await notifee.createChannel(INCOMING_CHANNEL_OPTIONS);
const notificationId = generateId();
const largeIcon = getNotificationLargeIconByUser(user);
if (isIOS) {
await getIosCategory();
}
await notifee.displayNotification({
title: title,
body: body,
id: notificationId,
android: {
channelId: callChannelId,
category: AndroidCategory.CALL,
circularLargeIcon: true,
color: AndroidColor.BLUE,
// Recommended to set importance to high
importance: AndroidImportance.HIGH,
ongoing: true,
largeIcon: largeIcon,
// smallIcon: 'name-of-a-small-icon', // optional, defaults to 'ic_launcher'.
pressAction: {
id: NOTIFICATION_ACTIONS_ID.acceptIncomingCall,
},
actions: [
{
title: '<span style="color: #FF0000;">Réfuser</span>',
pressAction: { id: NOTIFICATION_ACTIONS_ID.cancelIncomingCall },
},
{
title: '<span style="color: #00FF00;">Accepter</span>',
pressAction: { id: NOTIFICATION_ACTIONS_ID.acceptIncomingCall },
},
],
badgeCount: 1,
timeoutAfter: ONE_MINUTE,
autoCancel: false,
},
ios: {
categoryId: 'incoming-call',
attachments: [
{
// iOS resource
url: largeIcon,
thumbnailHidden: true,
},
],
foregroundPresentationOptions: {
alert: true,
sound: true,
},
critical: true,
},
data: {
notification: JSON.stringify({ ...notification, notificationId }),
},
});
}, |
Output from |
@mikehardy
So seems to be the same as #250 where the proposed fix is to downgrade from I downgraded and pressing notifications works now. 👍 |
Oh darn, that was supposed to be fixed in 4.1.0 |
@mikehardy I was testing with
|
+1 on this issue @notifee/react-native 5.3.0 Running on MacOS, on Android emulator Pixel_XL_API_30 I don't get any indication that the notification got pressed. Other things (getInitiialNotification & onForeGroundEvent) work when it's in other states, but when it's in the background a press on the notification just brings up the app and the AppState switches, but I can't find any way to determine that a notification press just happened. (Will accept workarounds!) (It doesn't trigger on iOS, either, but the onForegroundEvent works fine there.) |
+1 When app is killed, Downgrading targetSDK to 30 "solves" the problem for me (RN 0.68.2) |
+1 @mikehardy my logcat output seems pretty similar to @fabyeah 's above. Do you mind sharing if there's any plans to address this issue? |
Hello, we can't downgrade targetSdk to 30, because Play Store is not accepting it. What other workarounds do we have? |
My case: App is in QUIT state. I create a push with action after getting high priority remote data push. Since Obviously registering |
I am wondering why |
Looks like
|
It is returning
|
@mieszko4 I can confirm, I just tested
Returning Unfortunately this is not a solution, but posting it here just to confirm it. Really appreciated your research 👍🏽 |
I'm using react native 0.68.4 and targetSDK 33 and it's not fixed. |
A suggestion: everyone upgrade to current stable versions of software then try reproducing? That's a best practice, ends up saving more time then the apparent "possibly wasted time" of updating to current stable, in my experience |
@mikehardy Thank you for the suggestion, I'll give it a try right now, because today our app was rejected by google it requires |
@mikehardy What do you mean by current stable versions? Isn't |
stable but not current current stable is react-native 0.70.6, @notifee/react-native 7.1.0 https://github.com/invertase/notifee/releases So no, neither are current and stable and you have a high probability of chasing phantom issues that are already fixed, and you're requesting others attention for the same, potentially spending everyone's time inefficiently. |
Right, I agree. Just the problem is that there are breaking changes in react-native and associated packages so it is not straightforward to upgrade to the current stable versions (at least in my case). |
@mieszko4 I have I also I can confirm with @venux92 This is working for me. try {
reactContext = (ReactContext) context;
} catch (ClassCastException exception) {
return false; // <== forced to false
} Can I use this in production like a temporary solution until I upgrade to |
New Architecture is orthogonal. You don't have to use it. It is an option. Stated more directly: react-native-firebase does not even support New Architecture at all! Yet, you may use react-native-firebase with react-native 0.70.6 without problem https://github.com/mikehardy/rnfbdemo/blob/main/make-demo.sh There is no reason not to update to current stable versions prior to requesting other people's time investigating help on problems that may already be fixed. |
At the same time, open source is amazing - you've got all the source and if you've got some solution that works for you, use it! https://github.com/ds300/patch-package is something I use frequently myself. Though I typically use it only temporarily while I'm already on current stable versions and I'm working a PR through the upstream package.... |
@mikehardy thank you again for your guidance and support. |
Just wanted to share my findings. On Android 5 My point is the current implementation of This patch fixes that bug. However, it now makes Android 12 show taps as diff --git a/packages/react-native/android/src/main/java/io/invertase/notifee/NotifeeReactUtils.java b/packages/react-native/android/src/main/java/io/invertase/notifee/NotifeeReactUtils.java
index b60e6d4..805447c 100644
--- a/packages/react-native/android/src/main/java/io/invertase/notifee/NotifeeReactUtils.java
+++ b/packages/react-native/android/src/main/java/io/invertase/notifee/NotifeeReactUtils.java
@@ -210,12 +210,9 @@ class NotifeeReactUtils {
for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
&& appProcess.processName.equals(packageName)) {
- ReactContext reactContext;
-
- try {
- reactContext = (ReactContext) context;
- } catch (ClassCastException exception) {
- return true;
+ ReactContext reactContext = getReactContext();
+ if (reactContext == null) {
+ return false;
}
return reactContext.getLifecycleState() == LifecycleState.RESUMED; If I find some time I will check if this is an issue with current stable versions. |
I started fresh (https://reactnative.dev/docs/environment-setup) using function Screen() {
async function onDisplayNotification() {
// Request permissions (required for iOS)
await notifee.requestPermission()
// Create a channel (required for Android)
const channelId = await notifee.createChannel({
id: 'default',
name: 'Default Channel',
});
// Display a notification
await notifee.displayNotification({
title: 'Notification Title',
body: 'Main body content of the notification',
android: {
channelId,
//smallIcon: 'name-of-a-small-icon', // optional, defaults to 'ic_launcher'.
// pressAction is needed if you want the notification to open the app when pressed
pressAction: {
id: 'default',
},
},
});
}
return (
<View>
<Button title="Display Notification" onPress={() => onDisplayNotification()} />
</View>
);
} And I added On Android 12, after tapping on I cannot see the point of this |
Also, |
@mieszko4 With the following setup :
Passing quick actions to I think this problem should be considered as critical by the Notifee Team |
With apologies - just to set expectations, considering it critical or not does not magically make more hours appear in the day. It's an open source project, and all reasonable PRs will be merged + released. If this is something that affects your business, it may be worth it for you to prioritize development resources to investigate + fix |
Yes, the issue for me was also with Quick Actions. With #404 (comment) I just wanted to show the smallest reproducible code which is the cause of this issue. On the project, I am using the patch that I provided in that comment and it's been working great for me. |
I am sorry if I have been offensive. |
Not offensive - no worries - just wanted to make sure expectations were aligned. I maintain react-native repositories on contract and have a startup that's taking off right now, I write code for money, though I do enjoy it. I never have enough time in the day though, and don't personally have time for this one right now |
Massive thanks to @mieszko4 for fixing this issue! Released in 7.2.0 |
I was facing this issue after updating to TargetSdkVersion = 31 in 5.x.x of Notifee. *** Issue is observed in VIVO phones. I will check other devices and update here if issue is present in other devices |
I've a notification with two actions (accept call/ reject call).
handleOnForegroundEvent works fine.
And now I'm trying to add handleOnForegroundEvent: The notification get displayed in killed state and handleOnForegroundEvent fired once then when I pressed I can't get wich action get pressed because onBackgroundEvent not fired when I pressed.
Package.json
The text was updated successfully, but these errors were encountered: