Useful or not, from you.
react-native-firebase Android - Error: AndroidNotification: Missing required `channelId` property - Local Notifications

Issue

Currently local notifications on android api > 26 are not working because we are not populating the channelId.

Example of code on JS land:

  onNotification = (notification: Notification) => {
    firebase.notifications().displayNotification(notification);
  };

This happens because the Notification created has no way to infer the channel id from the RemoteMessage.Notification sent from Firebase, see api here:

https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/RemoteMessage.Notification

And how we are building it here: https://github.com/invertase/react-native-firebase/blob/d101813b5fc67c9f2da5d664f711b5113781163b/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotifications.java#L273-L288

See image: image

There is a question on SO for this exact problem: https://stackoverflow.com/q/46910621/710693

The way I got around this was to rebuild the notification object and pass the channelId as an additional property:

  onNotification = (notification: Notification) => {
    // eslint-disable-next-line
    console.log('onNotification: ', notification);

    const localNotification = new firebase.notifications.Notification()
      .setNotificationId(notification.notificationId)
      .setTitle(notification.title)
      .setSubtitle(notification.subtitle)
      .setBody(notification.body);

    if (Platform.OS === 'android') {
      localNotification._android._channelId = notification.data.channelId;
    }

    firebase.notifications().displayNotification(localNotification);
  };

Environment

Android

  1. Application Target Platform:

N/A

  1. Development Operating System:

N/A

  1. Build Tools:

N/A

  1. React Native version:

v53

  1. RNFirebase Version:

v4

  1. Firebase Module:

Notifications

That's a useful answer
Without any help

Hi, I could not set channel Id for android

onNotification = (notification: Notification) => {
    // modify your notification if required e.g. for this issue:
    notification.android.setChannelId(notification.data.channelId);
    // then display it by calling displayNotification
    firebase.notifications().displayNotification(notification);
  };

In the above code for me 'notification.data' does not contain 'channelId'. If I want to create Chanel, where I want to create it. Help me.