Add detailed instruction for creating custom notification channel and how to override it #7246
Unanswered
ahmedShaheer3
asked this question in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey there i have struggling for hours just know how would i create custome notificatication channel and over ride the default on. The only instruction i find in docs is firebase.json section which is following
https://rnfirebase.io/messaging/usage#firebasejson
under firebase.json section you have mentioned a property
"messaging_android_notification_channel_id": "high-priority"
This is the whole instruction i find in docs which is incomplete you need to edit more detail section like
Adding Custom notification channel
First step:
Edit Main.Activity.java with the following code
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelId = "custom_channel_id"; // Replace with your desired channel ID
String channelName = "custom_channel_name"; // Replace with your desired channel name
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel(channelId, channelName, importance);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
Note: Make sure to insert in onCreate function before onCreate() like this
@OverRide
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, R.style.SplashTheme, true);
// Change the importance level of the default channel (if on Android Oreo or above)
// Create a custom channel with HIGH importance (if on Android Oreo or above)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelId = "custom_channel_id"; // Replace with your desired channel ID
String channelName = "custom_channel_name"; // Replace with your desired channel name
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel(channelId, channelName, importance);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
super.onCreate(null);
}
Your are making custom notification channel with priority high so that notification banner will be displayed
Second step:
Create firebase.config on your root folder i.e // /firebase.json (if not exits)
Third step:
paste this code in firebase.json
{
"react-native": {
"messaging_android_notification_channel_id": "custom_channel_id"
}
}
By this you are overriding the default fcm channel .
Note: Make sure the custom_channel_id be same
Beta Was this translation helpful? Give feedback.
All reactions