react-native-fcm
react-native-fcm copied to clipboard
Failed to post notification on channel "null"
Getting this issue from Android 8 and above. The notifications works fine on iOS upto iOS 12 and below Android 8.
- RN :0.51.0 and react FCM: 16.2.3
- Android 8 pixel simulator
- Foreground
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 thanks for your help will try out the solution.
@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.
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);
I have the same issue when my App is in the background. Can anyone help us?
once you create a notification channel this issue will fix.
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??
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
now its shows below error
instead of channel "null" its showing channel id am passing from payload
We switched to using react-native-fcm
that solved this problem for us