Hello team,
1. Summary
I'm trying to implement a simple foreground service notification and everytime I create a notification it creates as a dismissable notification.
2. Enviroment
expo: 53.0.19
react-native: 0.79.5
react: 19.0.0
3. Platform
This problem happened on:
- Android Emulator API 35
- Android Device Version 15
4. Steps to problem
- Install @notifee/react-native:
npm install @notifee/react-native
- Generate development build:
eas build --profile android --platform development
- Install development build on device and on emulator
3.a. on Emulator, create prebuild to generate necessary files to run on emulator.
- Register the foreground service on my
App.js file
import notifee from '@notifee/react-native';
notifee.registerForegroundService(notification => {
return new Promise(() => {
console.log('Foreground service:', notification);
});
});
- Create a notification
const handleStartNotificationService = async () => {
const channelId = await notifee.createChannel({
id: 'foreground-service-notification',
name: 'Test channel',
importance: AndroidImportance.HIGH,
visibility: AndroidVisibility.PUBLIC,
});
try {
await notifee.displayNotification({
title: 'Foreground service',
body: 'This notification will exist for the lifetime of the service runner',
android: {
channelId,
asForegroundService: true,
color: '#0020FF',
colorized: true,
importance: AndroidImportance.HIGH,
visibility: AndroidVisibility.PUBLIC,
},
});
} catch (error) {
console.error('Error starting notification service:', error);
}
};
- Call in on a button
<Button title={'PRESS ME'} onPress={handleStartNotificationService} />
- On pressing notification is created
7.a. a console.log on notification inside my registerForegroundService shows the following:
{"android": {"asForegroundService": true, "autoCancel": true, "badgeIconType": 2, "channelId": "foreground-service-notification", "chronometerDirection": "up", "circularLargeIcon": false, "color": "#0020FF", "colorized": true, "defaults": [-1], "groupAlertBehavior": 0, "groupSummary": false, "importance": 4, "lightUpScreen": false, "localOnly": false, "loopSound": false, "ongoing": false, "onlyAlertOnce": false, "showChronometer": false, "showTimestamp": false, "smallIcon": "ic_launcher", "visibility": 1}, "body": "This notification will exist for the lifetime of the service runner", "data": {}, "title": "Foreground service"}
- On sliding notification horizontally it is succesfully dismissed
4.a Expected behavior
On step 8. Notification stays fixed
5. Final considerations
I would love to use this library but I couldnt figure it out how to make this work as I intend it to.
Thanks in advance for anyone trying to help, I will work a few days more to try and find a solution. If I succeed I will post it here.
Hello team,
1. Summary
I'm trying to implement a simple foreground service notification and everytime I create a notification it creates as a dismissable notification.
2. Enviroment
3. Platform
This problem happened on:
4. Steps to problem
npm install @notifee/react-nativeeas build --profile android --platform development3.a. on Emulator, create prebuild to generate necessary files to run on emulator.
App.jsfile7.a. a console.log on notification inside my registerForegroundService shows the following:
{"android": {"asForegroundService": true, "autoCancel": true, "badgeIconType": 2, "channelId": "foreground-service-notification", "chronometerDirection": "up", "circularLargeIcon": false, "color": "#0020FF", "colorized": true, "defaults": [-1], "groupAlertBehavior": 0, "groupSummary": false, "importance": 4, "lightUpScreen": false, "localOnly": false, "loopSound": false, "ongoing": false, "onlyAlertOnce": false, "showChronometer": false, "showTimestamp": false, "smallIcon": "ic_launcher", "visibility": 1}, "body": "This notification will exist for the lifetime of the service runner", "data": {}, "title": "Foreground service"}4.a Expected behavior
On step 8. Notification stays fixed
5. Final considerations
I would love to use this library but I couldnt figure it out how to make this work as I intend it to.
Thanks in advance for anyone trying to help, I will work a few days more to try and find a solution. If I succeed I will post it here.