Please provide the following:
SDK Version: 38.0.3
Platforms: Android
In my code, I am using React’s useEffect hook to modify Notification.setNotificationHandler to return the NotificationBehaviour according to the current chat room id. However, the Android device still displays the notification when messages are received when viewing the chat room. On iOS, there is no such issue and notifications are not displayed when messages from the chat room are received while viewing the chat room. The code looks something like this:
useEffect(() => {
Notifications.setNotificationHandler({
handleNotification: async (notification) => {
let body;
if (Platform.OS === 'android') {
body = (notification.request.content.data as AndroidNotificationData)
} else if (Platform.OS === 'ios') {
body = (notification.request.content.data as IOSNotificationData).body
}
if (body && body.id.toString() === group.id.toString()) {
console.log("Do not show")
return {
shouldShowAlert: false,
shouldPlaySound: false,
shouldSetBadge: false,
priority: Notifications.AndroidNotificationPriority.MIN
}
}
return {
shouldShowAlert: true,
shouldPlaySound: false,
shouldSetBadge: false,
priority: Notifications.AndroidNotificationPriority.MAX
}
}
})
return () => {
console.log("Unmounting")
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: false,
shouldSetBadge: false,
priority: Notifications.AndroidNotificationPriority.MAX
})
})
}
}, [])
In both cases, the “Do not show” is displayed on my console.
1 Like
aryk
July 18, 2020, 1:23am
2
Im getting the exact same behavior. SDK 38. iOS behaves correctly. Android expo app does not.
getfu
July 24, 2020, 3:28am
3
just had a similar issue in iOS, we had previously set, iosDisplayInForeground: true in our app.json.
setting this to false, allowed Notifications.setNotificationHandler to do its thing.
Are you able to control whether the notification appears in the foreground with Android?
aryk
July 31, 2020, 9:14pm
5
I still haven’t been able to resolve it. As far as I know, there is no iosDisplayInForeground type option for android.
Has anyone managed to solve this?
aryk
July 31, 2020, 11:54pm
6
Just to clarify, I’m using the SKD38 with useNextNotificationsApi: true. Could that be the reason why?
Really curious that no one is experiencing this with android…
getfu
August 5, 2020, 12:22am
7
sorry I wasn’t more specific. yes, the notification still shows in android after this change.
aryk
August 5, 2020, 9:12pm
8
Hey guys, just got fixed today after I reported it!
opened 01:47PM - 04 Aug 20 UTC
closed 12:06PM - 05 Aug 20 UTC
Android
Notifications
## 🐛 Bug Report
### Summary of Issue
Using useNextNotifications: true and… running:
```ts
Notifications.setNotificationHandler({
handleNotification: async (notification) => {
return {
shouldShowAlert: false,
shouldPlaySound: false,
shouldSetBadge: false,
}
}
})
```
The notification still shows up at the top while the app is running in Android (but iOS works correctly). My notification config section:
```
"notification": {
"iosDisplayInForeground": false,
"androidMode": "default"
},
```
### Environment - output of `expo diagnostics` & the platform(s) you're targeting
Expo CLI 3.21.13 environment info:
System:
OS: macOS Mojave 10.14.6
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 14.5.0 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.13.4 - /usr/local/bin/npm
IDEs:
Android Studio: 4.0 AI-193.6911.18.40.6514223
Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
npmPackages:
expo: ^38.0.8 => 38.0.8
react: 16.11.0 => 16.11.0
react-dom: 16.11.0 => 16.11.0
1 Like
system
Closed
September 4, 2020, 9:12pm
9
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.