react-native-push-notification
react-native-push-notification copied to clipboard
How to handle notification actions clicks on android on background/killed states
Hey guys, basically the situation is i receive a ( data-only ) remote message and then push a local notification and add actions to it, but when it comes to handling em in background and quit state, i click the actions nothing happens here's the code i call on my index.js
PushNotification.configure({
onNotification: function (notification) {
const appState = AppState.currentState;
if (appState !== 'active') {
if (!notification.userInteraction) {
PushNotification.localNotification({
channelId: '// some chennel id',
title: notification.data.title,
message: notification.data.message,
priority: 'high',
actions: JSON.parse(notification.data.actions).map(
(item: any) => item.title,
),
smallIcon: 'ic_notification_icon',
largeIcon: '',
bigText: '',
subText: '',
bigPictureUrl: '',
userInfo: notification.data,
});
} else {
const actionIdentifier = notification.action;
if (!actionIdentifier) return;
switch (actionIdentifier) {
case 'YES':
console.log(actionIdentifier);
break;
case 'NO':
console.log(actionIdentifier);
break;
case 'CHECK':
// open the app and navigate to a notifs screen
break;
default:
console.log('No actionIdentifier selected', actionIdentifier);
break;
}
}
}
},
});