notifee: App does not open on notification click (should "pressAction" be a default without needing to specify it?)
Apparent bug
It seems like the app does not open when clicking the notification body.
Environment
react-native: 0.66.4
@notifee/react-native: 4.0.1
,
device/api: Pixel_5_API_31
Reproduction steps
npx react-native init repro
npm i @notifee/react-native
- add
android:exported="true"
toAnroidManifest.xml
- update
build.gradle
withcompileSdkVersion = 31 targetSdkVersion = 31
- add provided code of minimal example
- build app
- click button to display notification
- minimize app and click notification
- in my case, the notification disappears after a short moment but the app does not open
minimal example:
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React from 'react';
import {View, Button} from 'react-native';
import notifee from '@notifee/react-native';
const App = () => {
async function onDisplayNotification() {
const channelId = await notifee.createChannel({
id: 'default',
name: 'Default Channel',
});
await notifee.displayNotification({
title: 'title',
body: 'body',
android: {
channelId,
pressAction: {
id: 'default',
},
},
});
}
return (
<View>
<Button
title="Display Notification"
onPress={() => onDisplayNotification()}
/>
</View>
);
};
export default App;
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 5
- Comments: 44 (14 by maintainers)
This works for me with flavors / applicationIdSuffice:
Just updating here on status, the latest release v4.1.0 contains a fix for apps targeting API 31 and devices running Android 12.
The solution for me, thanks team
@alexanderdavide I added an action to
actions
array inandroid
property when creating trigger notification, here’s sample code and here’s more info:I found out that I might be encountering a different issue, notifications don’t open app even on older versions (as I mentioned in previous comment, I have
API 30
which is Android 11). Today I tested all older versions down to Android 9, none of them worked.But when I tried example project from the repo, it worked. So I’m assuming there’s something wrong with my setup. I’ll let you know if I manage to fix it or figure out what the issue is.
this is definitely possible, it will be a breaking change for developers who haven’t set a
pressAction
intentionally. My main hesitation to do this is for the scenario you don’t want a pressAction, might be harder to specify that. But in terms of implementation, this would be very simple to do. It’s just on the js level to addpressAction: { id: 'default' }
as a default value if not set.@alexanderdavide I didn’t test it on API 31, so I’m not sure, but I think the workaround from #250 is still necessary. I was already on that SDK version mentioned in the workaround.
@effektsvk @mikehardy @helenaford To clarify: Should this work on API 31 too? I’ve just tried this
on the setup I’ve opened the issue with but opening the app upon notification click remains dysfunctioning, hence I’m still working on 30 as #250 proposes which works with just
pressAction.id
defined.@effektsvk ah yeah, thanks. That’s good to know. I think that is the issue 🤔 It probably makes sense to default to
id: default
if pressAction isn’t defined.Okay, I might be able to take a look at it today, if I make some sense of it, I’ll let you know. (I’m a bit scared because I don’t have a lot of experience with android environment and packages, but I guess it’s still just code, nothing to worry about, right? 😅😅)
Again, thank you very much for your help! ❤️
@alexanderdavide In
android/app/build.gradle
we have product flavors defined like this, and then build the app withreact-native run-android --appIdSuffix development --variant deploymentDevelopmentDebug
:@effektsvk Sorry, I thought your device is on API 30 but you may still have
targetSdkVersion
on 31. So, you had the issues while being ontargetSdkVersion
30? Then there must be another problem. This is mybuildscript.ext
with the working workaround:@mikehardy Thanks. I always try to give the best reports I can to make your lives a little easier.
@effektsvk Actually, in my real application where I experience this problem I’m using trigger notifications too. For this report, I opted for a simpler example.