react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

AndroidNotification: Missing required `channelId` property

Open smemamian opened this issue 8 years ago • 3 comments

when app is foreground I get yellow error:

YellowBox.js:80 Possible Unhandled Promise Rejection (id: 0):
Error: AndroidNotification: Missing required `channelId` property
Error: AndroidNotification: Missing required `channelId` property
    at AndroidNotification.build (blob:http://localhost:8081/a9bbbd91-a1cf-4143-8ed0-ed77cccfe5e0:172069:17)
    at Notification.build (blob:http://localhost:8081/a9bbbd91-a1cf-4143-8ed0-ed77cccfe5e0:171679:75)
    at Notifications.displayNotification (blob:http://localhost:8081/a9bbbd91-a1cf-4143-8ed0-ed77cccfe5e0:170690:86)
    at blob:http://localhost:8081/a9bbbd91-a1cf-4143-8ed0-ed77cccfe5e0:173153:53
    at EventEmitter.emit (blob:http://localhost:8081/a9bbbd91-a1cf-4143-8ed0-ed77cccfe5e0:162784:37)
    at blob:http://localhost:8081/a9bbbd91-a1cf-4143-8ed0-ed77cccfe5e0:170658:36
    at EventEmitter.emit (blob:http://localhost:8081/a9bbbd91-a1cf-4143-8ed0-ed77cccfe5e0:162784:37)
    at blob:http://localhost:8081/a9bbbd91-a1cf-4143-8ed0-ed77cccfe5e0:162686:30
    at RCTDeviceEventEmitter.emit (blob:http://localhost:8081/a9bbbd91-a1cf-4143-8ed0-ed77cccfe5e0:3478:37)
    at MessageQueue.__callFunction (blob:http://localhost:8081/a9bbbd91-a1cf-4143-8ed0-ed77cccfe5e0:2384:44)

my codes:

import firebase from 'react-native-firebase';

function displayNotificationFromCustomData(message){
  console.log('masoud masoud')
  if(message.data && message.data.title){
    let notification = new firebase.notifications.Notification();
      notification = notification
      .setTitle(message.data.title)
      .setBody(message.data.body)
      .setData(message.data)
      .setSound("default")


      notification.android.setPriority(firebase.notifications.Android.Priority.High) /// set to High
      notification.android.setChannelId("teamcide")  ///for android 8.0 and above

      const channel = new firebase.notifications.Android.Channel(
      "daily",
      "Reminders",
      firebase.notifications.Android.Importance.High
    ).setDescription("Reminds you....");

    firebase.notifications().android.createChannel(channel);
    firebase.notifications().displayNotification(notification);
  }
}


// these callback will be triggered only when app is foreground or background
export function registerAppListener(){
  console.log('Ok')
  this.notificationListener = firebase.notifications().onNotification(notification => {
    firebase.notifications().displayNotification(notification);
  })
  this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
    const notif = notificationOpen.notification;

    console.log(notif)

    setTimeout(()=>{
      alert(`User tapped notification\n${notif.notificationId}`)
    }, 500)
  });

  this.onTokenRefreshListener = firebase.messaging().onTokenRefresh(token => {
    console.log("TOKEN (refreshUnsubscribe)", token);
  });

  this.messageListener = firebase.messaging().onMessage((message) => {
    console.log('masoud')
    console.log(message)
    displayNotificationFromCustomData(message);
  });

}

smemamian avatar Aug 19 '18 16:08 smemamian

Error: AndroidNotification: Missing required channelId property - your notification is missing a channelId like the error says 😋

Also firebase.notifications().android.createChannel(channel); is a promise so it's asynchronous. You need to await it before creating your notification.


Loving react-native-firebase and the support we provide? Please consider supporting us with any of the below:

Salakar avatar Aug 21 '18 12:08 Salakar

According to the docs, firebase.notifications().android.createChannel(channel); is still not a asynchronous. Maybe Mr. @Salakar can give an example of working code.

achmadk avatar Oct 25 '18 10:10 achmadk

channelId does not match! notification.android.setChannelId("teamcide") --> notification.android.setChannelId("daily")

quangvietntd avatar Nov 06 '18 15:11 quangvietntd