react-native-background-geolocation
react-native-background-geolocation copied to clipboard
Continuous(WhenInUse) Location Tracking is not working in Android
Continues Location tracking is not working in Android(works fine in IOS) with below configuration. I can see the heartbeat(onLocation) calls are being happened but not onLocation calls. Please review and provide a solution
-->
Your Environment
- Plugin version: ^4.9.4
- Platform: iOS or Android.
- OS version: Android 10
- Device manufacturer / model: Samsung S9 Plus
- React Native version (
react-native -v): )0.70.9 - Plugin config
export const config: Config = {
locationAuthorizationRequest: 'WhenInUse',
backgroundPermissionRationale: {
title: "Allow {applicationName} to access to this device's location when in use?",
message: 'In order to track your activity in the background, please enable when in use location permission',
positiveAction: 'Change to when in use',
negativeAction: 'Cancel',
},
// Notification is required for newer version on android
notification: {
title: '',
text: '',
},
// Geolocation Config
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
disableElasticity: true,
distanceFilter: 200,
stopTimeout: 5,
locationUpdateInterval: 30000,
fastestLocationUpdateInterval: 30000,
logLevel: BackgroundGeolocation.LOG_LEVEL_ERROR,
stopOnTerminate: true, // <-- Allow the background-service to continue tracking when user closes the app.
enableHeadless: false,
startOnBoot: false, // <-- Auto start tracking when device is powered-up.
batchSync: false, // <-- [Default: false] Set true to sync locations to server in a single HTTP request.
autoSync: true, // <-- [Default: true] Set true to sync each location to server as it arrives.
heartbeatInterval: 10 * 60,
preventSuspend: true,
disableLocationAuthorizationAlert: true,
};
static configureListeners() {
const locationSubscription = BackgroundGeolocation.onLocation(this.onLocationChange);
const HBSubscription = BackgroundGeolocation.c(this.onHeartbeat);
const providerChangeSubscription = BackgroundGeolocation.onProviderChange(this.onProviderChange);
const onGeoFenceEvent = BackgroundGeolocation.onGeofence(this.onGeoFence);
this.GeoLocationSubscriptions = [locationSubscription, providerChangeSubscription, onGeoFenceEvent, HBSubscription];
}
static async init(routeIds: number[]): Promise
{ this.routeIds = routeIds; if (this.GeoLocationSubscriptions.length > 0) { if (!store.getState()?.geolocation.trackingStatus) { GeoLocation.startTracking(); } return this.initializationResponse.SUCCESS; } logUtil.info('INFO', 'GeoLocation init with', routeIds); try { await GeoLocation.initializeGeoConfig(); GeoLocation.startTracking(); return this.initializationResponse.SUCCESS; } catch (error) { if (error === 'Permission denied') { return this.initializationResponse.LOCATION_PERMISSION_DENIED; } return this.initializationResponse.FAILED; } } static async initializeGeoConfig() { logUtil.info('INFO', 'GeoLocation Config'); if (this.GeoLocationSubscriptions.length > 0) { logUtil.info('INFO', 'GeoLocation Config Already Done'); return; } // Wire up event-listeners. GeoLocation.configureListeners(); BackgroundGeolocation.ready(config).then(_state => { if (!_state.enabled) { if (!GeoLocation.requestPermission()) { throw 'Permission denied'; } BackgroundGeolocation.ready(config); } }); } static async startTracking() { if (this.GeoLocationSubscriptions.length == 0) await GeoLocation.initializeGeoConfig(); logUtil.info('INFO', 'GeoLocation start'); const state = await BackgroundGeolocation.start(); logUtil.info('INFO', 'GeoLocation start state', state); store.dispatch(onGPSStart(state.enabled)); BackgroundGeolocation.getCurrentPosition(currentPositionConfig) .then(location => GeoLocation.setLocation(location)) .catch(() => {}); logUtil.info('INFO', 'GeoLocation start Successful'); }
Plugin version: ^4.9.4
see the CHANGELOG and update.
OS version
??
Device manufacturer / model: All Andorid
Oh really…”all”.
OS version : Android 10 Device manufacturer / model: Samsung S9 Plus
We tested few other devices in Android but no luck. Its tracking when we test with 'Mock GPS' like apps
Read the wiki “Philosophy of Operation and go outside and move >= 1km
Plugin version: ^4.9.4
see the CHANGELOG and update.
OS version
??
Device manufacturer / model: All Andorid
Oh really…”all”.
Updated to 4.9.4 but continuous tracking is still not working in android, but IOS is working well. Any suggestion or pointer to fix this android issue?
4.9.4 is from December last year. Update to the latest version.
Do you know that automatic triggering of location-tracking in the background is impossible with WhenInUse? You must MANUALLY call .changePace(true) (after calling .start()) while your app is in the foreground.
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.