Hi!
I want to show a notification banner using this code:
postLocalNotification(title: string, body: string, data: object, id?: number) {
let localNotification = new Notification({
body: body,
title: title,
sound: undefined,
silent: false,
category: "SOME_CATEGORY",
userInfo: data,
extra: "data",
});
Notifications.postLocalNotification(localNotification.payload, id ? id : Date.now())
}
I get the notification posted in the status bar, with the title and the body, but it doesn't show the banner in the upper part of the screen, not in foreground not in background.
In ios it works perfect.
React Native: 0.61.5
React Native Notifications: 3.1.2
Can somebody help?
Thanks
Hi,
We finally found that this behaviour was due the priority of the channel. We change it to NotificationManager.IMPORTANCE_HIGH and it started working as we wanted.
You can change this paremeter inside de class "PushNotification.java", in the function getNotificationBuilder.
protected Notification.Builder getNotificationBuilder(PendingIntent intent) {
String CHANNEL_ID = "channel_01";
String CHANNEL_NAME = "Channel Name";
final Notification.Builder notification = new Notification.Builder(mContext)
.setContentTitle(mNotificationProps.getTitle())
.setContentText(mNotificationProps.getBody())
.setContentIntent(intent)
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true);
int resourceID = mContext.getResources().getIdentifier("notification_icon", "drawable", mContext.getPackageName());
if (resourceID != 0) {
notification.setSmallIcon(resourceID);
} else {
notification.setSmallIcon(mContext.getApplicationInfo().icon);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
CHANNEL_NAME,
NotificationManager.IMPORTANCE_HIGH);
final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(channel);
notification.setChannelId(CHANNEL_ID);
}
return notification;
}
Understanding that not everybody wants to use this behaviour, I think that it would be great if this library offers the change to create diferent channels with different priorities from the react native API.
Thanks for your job anyway, this is great!
Most helpful comment
Hi,
We finally found that this behaviour was due the priority of the channel. We change it to NotificationManager.IMPORTANCE_HIGH and it started working as we wanted.
You can change this paremeter inside de class "PushNotification.java", in the function getNotificationBuilder.
Understanding that not everybody wants to use this behaviour, I think that it would be great if this library offers the change to create diferent channels with different priorities from the react native API.
Thanks for your job anyway, this is great!