react-native-foreground-service
react-native-foreground-service copied to clipboard
Notification is not displaying the correct title, text and icon
I am using the code from your example application, but the notification is not showing anything from notificationConfig. The title is testApp is running, message is Tap for more information or to stop the app and there is no icon at all.
Code snippet:
startForegroundService = async () => {
if (Platform.OS !== 'android') {
console.log("Foreground service is available only on Android!");
return;
}
if (Platform.Version >= 26) {
const channelConfig = {
id: 'ForegroundServiceChannel',
name: 'Notification Channel',
description: 'Notification Channel for Foreground Service',
enableVibration: true,
importance: 2
};
try {
await VIForegroundService.createNotificationChannel(channelConfig);
} catch (e) {
console.log('HomePage', e);
}
}
const notificationConfig = {
channelId: 'ForegroundServiceChannel',
id: 3456,
title: 'MyTestApplication',
text: 'Notification test text',
icon: 'ic_notification',
priority: 1
};
if (Platform.Version >= 26) {
notificationConfig.channelId = 'ForegroundServiceChannel';
}
await VIForegroundService.startService(notificationConfig);
}
Add an icon with name ic_notification in resource of android.
Thanks @ipa127001! To provide a bit more detail, I added my icon as an ic_notification.png file to the following directories which fixed all of the issues mentioned in this ticket:
/android/app/src/main/res/mipmap-hdpi /android/app/src/main/res/mipmap-mdpi /android/app/src/main/res/mipmap-xhdpi /android/app/src/main/res/mipmap-xxhdpi /android/app/src/main/res/mipmap-xxxhdpi
did you fix the problem by adding a image file i also same issue please help
Yes, the ic_notification.png file should be a PNG image file.
What about title and text? Can it be changed?
Oh sorry, I answered my own question. It's seems that without icon text and intent doesn't change. Seems a little bit crazy, but it works. Sorry once more.