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.