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

Failed to post notification on channel "null"

Open rjsajnani1 opened this issue 5 years ago • 9 comments

Getting this issue from Android 8 and above. The notifications works fine on iOS upto iOS 12 and below Android 8.

  1. RN :0.51.0 and react FCM: 16.2.3
  2. Android 8 pixel simulator
  3. Foreground screen shot 2018-09-24 at 3 10 38 pm 1

rjsajnani1 avatar Sep 25 '18 06:09 rjsajnani1

I found that notifications stopped working for me after I upgraded my phone to Android 8.0

Passing a channel (string) through as part of the custom_notification block made my notifications work again.

(It uses it here:)

https://github.com/evollu/react-native-fcm/blob/b587872fadff2bb989fd8c9ac8bd1046e345498c/android/src/main/java/com/evollu/react/fcm/SendNotificationTask.java#L81

christianchown avatar Sep 30 '18 14:09 christianchown

@christianchown thanks for your help will try out the solution.

rjsajnani1 avatar Oct 01 '18 13:10 rjsajnani1

@christianchown i did try it out but still was getting the same error. I can see the channel in my notifications but when ever i pass a notification from FCM or server with the same channel id. I still get the same error.

Can u provide me a example of your code so i can try to see how it looks. I dont use any custom notifications. I have also added <meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="default"/> in my AndroidMainfest.xml

await FCM.createNotificationChannel({ id: 'default', name: 'Default', description: 'general usage', priority: 'high' }) before my registerAppListener as well.

rjsajnani1 avatar Oct 03 '18 08:10 rjsajnani1

I just noticed I don't have a default_notification_channel_id - I should probably add one. I've also set up my project for local notifications as specified in https://github.com/evollu/react-native-fcm#android

I send notifications differently depending on whether the platform is Android or iOS:

function getPayload(platform, title, body, extraData = null, badge = 0) => {
  const payload = {};
  if (platform === 'android') {
    const large_icon = // url
    const color = // #RGB
    const channel = // channel ID
    payload.data = {
      custom_notification: JSON.stringify({
        title,
        body,
        priority: 'high',
        sound: 'default',
        click_action: 'ACTION',
        large_icon,
        big_text: body,
        icon: 'ic_notif',
        color,
        show_in_foreground: true,
        badge: badge.toString(),
        channel,
        ...(extraData || {}),
      }),
    };
  } else {
    payload.notification = {
      title,
      body,
      badge: badge.toString(),
    };
    if (extraData) payload.data = extraData;
  }
  return payload;
};


const payload = getPayload(platform, title, body, extraData, badge);
const response = await firebase.messaging().sendToDevice(token, payload);

christianchown avatar Oct 03 '18 09:10 christianchown

I have the same issue when my App is in the background. Can anyone help us?

stsiushkevich avatar Oct 11 '18 14:10 stsiushkevich

once you create a notification channel this issue will fix.

DV31 avatar Oct 16 '18 06:10 DV31

createNotificationChannel is undefined on my FCM object.

I can NOT do

FCM.createNotificationChannel({ id: 'default', name: 'Default', description: 'general usage', priority: 'high' })

Do I need to upgrade??

wmonecke avatar Dec 12 '18 10:12 wmonecke

hi @christianchown

am I missing something?

i have tried adding below as described NotificationCompat.Builder notification = new NotificationCompat.Builder(mContext, bundle.getString("channel"))

i also add below in manifest

<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="default"/>

and i am hitting notification from postman as below image

now its shows below error instead of channel "null" its showing channel id am passing from payload image

yusuf987 avatar Feb 28 '19 10:02 yusuf987

We switched to using react-native-fcm that solved this problem for us

rjsajnani1 avatar Mar 01 '19 03:03 rjsajnani1