react-native-background-geolocation icon indicating copy to clipboard operation
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

Open GurjeetLamba opened this issue 2 years ago • 6 comments

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

GurjeetLamba avatar Jul 24 '23 05:07 GurjeetLamba

See https://dontkillmyapp.com

christocracy avatar Jul 24 '23 11:07 christocracy

but how can we make these settings on different user's devices , that will not be possible

GurjeetLamba avatar Jul 24 '23 12:07 GurjeetLamba

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

christocracy avatar Jul 24 '23 12:07 christocracy

// 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 ?

GurjeetLamba avatar Jul 24 '23 12:07 GurjeetLamba

What I need to do here in place of showMyConfirmDialog

You show your own custom dialog to your user, with your own custom instructions.

christocracy avatar Jul 24 '23 13:07 christocracy

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar May 07 '24 01:05 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar May 22 '24 01:05 github-actions[bot]