Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 28480

Handle native service notification with react-native-firebase (Android)

$
0
0

I've been using react-native-firebase to handle receiving remote push notifications + displaying local notifications. The code below has been sufficient to handle notifications sent during active, background, and terminated states.

notifications().onNotificationOpened(async notificationOpen => {
    // is called when app is active or background and notification is clicked
    // here is where I expect to handle the user clicking the native notification (see below), 
    // but it is not called
})

notifications().onNotification(async notification => {
    // is called when app is in foreground and receives remote push notification
})

notifications().getInitialNotification().then(async notificationOpen => {
    // is called when app is opened from terminated state when clicking on notification
})

Recently, I had to make a custom native service which occasionally displays a notification. However when the user clicks on this notification, the app properly opens/foregrounds, but firebase does not invoke any of its callbacks as it does when receiving remote notification/handling local notifications generated using firebase's library. It makes no difference the activity state of my application; even if in the foreground, clicking the notification does not invoke firebase's callbacks. Here is how I am creating the notification. I have verified the channel ID is the same one that firebase creates. Not sure where else to go from here...

Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

Notification notification = new NotificationCompat.Builder(this, 'push-channel')
    .setContentTitle("Notification Title")
    .setContentText("Notification Text")
    .setSmallIcon(R.drawable.ic_special)
    .setContentIntent(contentIntent)
    .setOngoing(true)
    .build();

I would like to have my react code respond to the user interacting with this native-built notification the same way it properly does when the user interacts with a notification created using notifications().displayNotification(new notifications.Notification(...)) If anyone has any ideas, that would be great!


Viewing all articles
Browse latest Browse all 28480

Trending Articles