Hello everyone!
I am trying to use notifee to implement a foreground service to track user location for a walking app. After around 5 minutes after the service is registered the task stops when on a physical device (works fine on the emulator), although the fs notification is still shown.
Current Behaviour: The foreground service task stops after around 5 minutes
Expected Behavior: Task continues to run until notifee.stopForegroundService() is called
Thank you for your time!
devices: samsung a13, Samsung galaxy a9
"@notifee/react-native":` "^7.5.0",
"react": "18.1.0",
"react-native": "0.70.5",
"expo": "~47.0.12",
notifee.registerForegroundService(() => {
return new Promise(async () => {
(async function trackLocation() {
const isTracking = await Location.hasStartedLocationUpdatesAsync(
LOCATION_TRACKING
);
if (isTracking) {
const location = await Location.getCurrentPositionAsync();
let latitude = location.coords.latitude;
let longitude = location.coords.longitude;
let accuracy = location.coords.accuracy;
// @a dispatch add coordinates to the coordinates array in the redux store (if accuracy is lower than 10m)
if (accuracy <= ACCURACY) {
if (USE_KFILTER) {
// @a implemented incremental kalman
var previousCorrected = JSON.parse(store.getState().previousCorrected.value)
previousCorrected = previousCorrected ? new State({mean: previousCorrected.mean, covariance: previousCorrected.covariance, index: previousCorrected.index}) : null
previousCorrected = kFilter.filter({previousCorrected, observation: [latitude, longitude] })
store.dispatch(setPreviousCorrected(JSON.stringify(previousCorrected)))
if (previousCorrected.index >=3) {
store.dispatch(addCoordinates({ latitude: previousCorrected.mean[0][0], longitude: previousCorrected.mean[1][0] }));
} else {
//@a add non-filtered coordinates for the first 3 locations
store.dispatch(addCoordinates({ latitude, longitude }));
}
} else {
store.dispatch(addCoordinates({ latitude, longitude }));
}
}
// @a calling the function recursively with 5000ms delay
setTimeout(() => {
trackLocation();
}, 5000);
} else {
// @a stop foreground service
await notifee.stopForegroundService();
}
})();
});
});
// @a set notification channel on android
const channelId = await notifee.createChannel({
id: "trackingLocation",
name: "Tracking Location",
lights: false,
vibration: false,
importance: AndroidImportance.HIGH,
});
// @a display notification for foreground service
notifee.displayNotification({
title: "Tracking Location",
body: "Flyr Go is currently tracking your location.",
android: {
channelId,
asForegroundService: true,
colorized: true,
ongoing: true,
pressAction: {
id: "default",
},
},
});
} ```
Hello everyone!
I am trying to use notifee to implement a foreground service to track user location for a walking app. After around 5 minutes after the service is registered the task stops when on a physical device (works fine on the emulator), although the fs notification is still shown.
Current Behaviour: The foreground service task stops after around 5 minutes
Expected Behavior: Task continues to run until notifee.stopForegroundService() is called
Thank you for your time!
devices: samsung a13, Samsung galaxy a9
"@notifee/react-native":` "^7.5.0",
"react": "18.1.0",
"react-native": "0.70.5",
"expo": "~47.0.12",