react-native-background-geolocation
react-native-background-geolocation copied to clipboard
Tracking is not working if app is not opened for 2 days and started working after opening the app again
If we have not opened the app for 2 days , didn't get the desired tracking results , but it worked again if opened the app again , which is not as expected , Tracking should work even if app is terminated .
Your Environment
-
Plugin version:^4.12.1
-
Platform: Android
-
OS version:12
-
Device manufacturer / model: OPPO CPH2095
-
React Native version (
react-native -v): 0.64 -
Plugin config const state = await BackgroundGeolocation.ready({
url: API_URL+API_ENDPOINTS.SAVELOCATION,
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE, desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH, distanceFilter: 10,
stopTimeout: 5, locationTemplate: '{"Latitude":<%= latitude %>,"Longitude":<%= longitude %>,"TimeStamp": "<%= timestamp %>"}', locationAuthorizationRequest: 'Always', backgroundPermissionRationale: { title: "Allow {applicationName} to access this device's location even when closed or not in use.", message: "This app collects location data to enable recording your trips to work and calculate distance-travelled.", positiveAction: 'Change to "{backgroundPermissionOptionLabel}"', negativeAction: 'Cancel' }, headers: { authorization: "Bearer " + getToken.data.Token, source: source }, params: { ClientId: respo_storage.data.ClientId, }, batchSync: true, autoSync: true, maxDaysToPersist: 14, stopOnTerminate: false, startOnBoot: true, enableHeadless: true, });
Expected Behavior
Location should be tracked each time when device moves some distance when app is installed on the device
Actual Behavior
Location tracking is working in random cases but not everytime
See https://dontkillmyapp.com
but how can we make these settings on different user's devices , that will not be possible
See api docs DeviceSettings. You must instruct your users to do as required.
this plug-in implements Android APIs according to public api docs. Certain Android manufacturers violate the Android api.
It is a well-known and frustrating issue among the Android development community with no software solution.
https://issuetracker.google.com/issues/122098785?pli=1
// Is Android device ignoring battery optimizations?
let isIgnoring = await BackgroundGeolocation.deviceSettings.isIgnoringBatteryOptimizations();
if (!isIgnoring) {
BackgroundGeolocation.deviceSettings.showIgnoreBatteryOptimizations().then((request:DeviceSettingsRequest) => {
console.log(- Screen seen? ${request.seen} ${request.lastSeenAt});
console.log(- Device: ${request.manufacturer} ${request.model} ${request.version});
// If we've already shown this screen to the user, we don't want to annoy them.
if (request.seen) {
return;
}
// It's your responsibility to instruct the user what exactly
// to do here, perhaps with a Confirm Dialog:
showMyConfirmDialog({
title: "Settings request",
text: "Please disable battery optimizations for your device"
}).then((confirmed) => {
if (confirmed) {
// User clicked [Confirm] button. Execute the redirect to settings screen:
BackgroundGeolocation.deviceSettings.show(request);
}
});
}).catch((error) => { // Depending on Manufacturer/Model/OS Version, a Device may not implement // a particular Settings screen. console.warn(error); }); }
What I need to do here in place of showMyConfirmDialog ? Does I need to get the battery optimization settings for each android device or plugin provides something related to that ?
What I need to do here in place of showMyConfirmDialog
You show your own custom dialog to your user, with your own custom instructions.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.