react-native-background-geolocation: [Help Wanted]: Android terminated state
Required Reading
- Confirmed
Plugin Version
^4.17.4
Mobile operating-system(s)
- iOS
- Android
Device Manufacturer(s) and Model(s)
Poco F4
Device operating-systems(s)
Android 15
React Native / Expo version
0.74.2
What do you require assistance about?
Hey there!
The package works great in all states in iOS and in all but terminated state for Android. We bought a licence but haven’t been able to get it to work in Android terminated mode.
The Logger logs dont show any specific errors or warnings.
Could you also point us to the TypeScript type of the android headless task Event? Looking through the code / docs / wiki, we dont see any way to properly type received by the .registerHeadlessTask.
[Optional] Plugin Code and/or Config
import { captureException } from '@sentry/react-native';
import BackgroundGeolocation, {
Config,
} from 'react-native-background-geolocation';
import { NotificationChannelIds } from '~/constants/notification';
import i18n from '~/lib/i18n';
import { LocationErrorWithSetupError } from '~/types/locations/location-error';
import { errorLog, infoLog, successLog } from '~/utils/logging/logging-utils';
let setupState: 'idle' | 'ready' = 'idle';
type SuccessReturn = {
success: true;
message: string;
error?: never;
};
type ErrorReturn = {
success: false;
error: LocationErrorWithSetupError;
message: string;
};
export const setupBackgroundGeolocationConfig = async (): Promise<
SuccessReturn | ErrorReturn
> => {
try {
if (setupState === 'ready') {
infoLog('setupBackgroundGeolocationConfig:: Already ready');
return {
success: true,
message: 'BackgroundGeolocation is ALREADY ready',
};
}
infoLog(
'setupBackgroundGeolocationConfig:: Setting up BackgroundGeolocation',
);
const config: Config = {
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 100,
// activity recognitison
stopTimeout: 5,
stopOnTerminate: false,
startOnBoot: true,
showsBackgroundLocationIndicator: false,
enableHeadless: true,
allowIdenticalLocations: false,
disableElasticity: false,
disableLocationAuthorizationAlert: true,
disableMotionActivityUpdates: true,
foregroundService: true,
// android foreground notification
notification: {
title: 'Location Updates',
text: 'Your location is being tracked for safety updates',
channelName: 'Location Updates',
smallIcon: 'mipmap/ic_notification',
channelId: NotificationChannelIds.AndroidLocationForeground,
priority: BackgroundGeolocation.NOTIFICATION_PRIORITY_MIN,
},
backgroundPermissionRationale: {
title: i18n.t('Screens.Onboarding.BackgroundLocationDialogTitle'),
message: i18n.t('Screens.Onboarding.BackgroundLocationDialogMessage'),
positiveAction: i18n.t('Common.GoToSettings'),
negativeAction: i18n.t('Common.Cancel'),
},
// debug
debug: false,
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
maxDaysToPersist: 1,
};
await BackgroundGeolocation.ready(config);
successLog(
'setupBackgroundGeolocationConfig:: BackgroundGeolocation is: ready',
);
setupState = 'ready';
return { success: true, message: 'BackgroundGeolocation is NOW ready' };
} catch (error) {
errorLog('setupBackgroundGeolocationConfig:: error', error);
captureException(error);
setupState = 'idle';
return {
success: false,
error: 4,
message: `BackgroundGeolocation setup error: ${JSON.stringify(error)}`,
};
}
};
[Optional] Relevant log output
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (7 by maintainers)
The
paramsobject is generally the same as its correspondingonXxxevent (eg.onLocation).I’m not a TS expert. I come from the old-school, of pure JavaScript of 20 years ago, a la Crockford.