Good community, I am currently using the https://www.npmjs.com/package/cordova-plugin-gpslocation plugin to geolocalize the device when the app is in the foreground and background, when in the background I use the OnPause method and execute A setInterval to execute the method of the plugin to obtain coordinates every X time (GetCurrentPosition). MY PROBLEM is that when the screen is turned on it works perfectly and the Location icon appears in the notification bar but when the screen is off it seems to stop working and only recaptures coordinates when I turn on the screen.
I have the following permissions in the Android Manifest that is in the platform of Android besides that I added the property in the activity tag also in the manifest.
<Uses-permission android: name = "android.permission.ACCESS_FINE_LOCATION" />
<Uses-permission android: name = "android.permission.ACCESS_COARSE_LOCATION" />
<Uses-permission android: name = "android.permission.AUTHENTICATE_ACCOUNTS" />
<Uses-permission android: name = "android.permission.GET_ACCOUNTS" />
<Uses-permission android: name = "android.permission.READ_SYNC_SETTINGS" />
<Uses-permission android: name = "android.permission.WRITE_SYNC_SETTINGS" />
<Uses-permission android: name = "android.permission.RECEIVE_BOOT_COMPLETED" />
<Uses-permission android: name ="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<Uses-permission android: name = "android.permission.ACCESS_NETWORK_STATE" />
<Uses-permission android: name = "android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<Uses-permission android: name = "android.permission.WAKE_LOCK" />
<Uses-permission android: name = "android.hardware.location" />
<Activity <span style = "text-decoration: underline;"> android: alwaysRetainTaskState = "true" android: configChanges = "orientation | keyboardHidden | keyboard | screenSize | locale" android: label = "@ string / activity_name "Android: launchMode =" singleTop "android: name =" MainActivity "android: theme =" @ android: style / Theme.DeviceDefault.NoActionBar "android: windowSoftInputMode =" adjustResize ">
If someone can give me a help I would appreciate it or if you need to add some other property in the manifest or something else, Thank you very much.
It seems that the plugin works only on active state. Only plugins with background tracking works like your expectation .. There are many such plugins , Let me give you the one i am using https://www.npmjs.com/package/cordova-plugin-mauron85-background-geolocation
backgroundGeolocation.configure(callbackFn, failureFn, {
desiredAccuracy: 10, // for accuracy
stationaryRadius: 20,
distanceFilter: 30, // minimum distance threshold
interval: 60000
});
This saves a lot of battery and also works on interval and distance basis. takes sample either only when the device crosses some distance and/or on the specified time.. This will work when the app goes on background .. Thanks and happy coding :)