Expo Location and Task Manager not working on Android

Please provide the following:

  1. SDK Version: 37
  2. Platforms(Android/iOS/web/all): all

Hi there!

I am a strange problem with the Location Api and Task Manager, while geofencing on Android.

The below code works perfectly on IOS standalone and when ran through EXPO but when I make a standalone android app nothing happens, the task manager is running and has correctly received the coordinates of the geofenced areas as I can see it logging in the console but it does not detect when I entered/left a geofenced area.

Is there an extra step you need to do in order for it to work on android? can anyone please help.

CODE BELOW

const LOCATION_API = ā€˜background-location-taskā€™;

TaskManager.defineTask(LOCATION_API, ({ data: { eventType, region }, error }) => {
if (error) {
// check error.message for more details.
return;
}
if (eventType === Location.GeofencingEventType.Enter) {
const { identifier } = region
let identifierReturned = [
identifier
]
console.log(ā€˜GeoLocation Detected you have entered site -ā€™, identifierReturned)
store.dispatch(dispatchEnteredSite(identifierReturned));

} else if (eventType === Location.GeofencingEventType.Exit) {
    const { identifier } = region
    let identifierReturned = [
        identifier
    ]
    store.dispatch(dispatchLastSite(identifierReturned));
    console.log('Left Site Dispatched to Redux Store',identifierReturned)
}

});

startGeofencing = async () => {
Analytics.logEvent(ā€˜Ran_Functionā€™, { name: ā€˜startGeofencingā€™});
const { status } = await Location.requestPermissionsAsync();
if (status === ā€˜grantedā€™) {
console.log(ā€œPermissions granted, fetching current locationā€)
const loc = await Location.getCurrentPositionAsync();
console.log("Current Location: ", loc)
this.setState({
currentLocation: loc
})
if (!TaskManager.isTaskDefined(ā€˜LOCATION_APIā€™)) {
Location.startGeofencingAsync(LOCATION_API, this.props.coorinatesForApi), {
accuracy: Location.Accuracy.BestForNavigation,
};
}}
};

1 Like

Hey there!

As you can see here I am having somewhat the same issue. Have you tried running it on an AVD device? (Android simulator). For me, through the expo app, it works flawless every single time in AVD. On iOS physical device with expo custom, it works flawless. On iOS in production, flawless. Android device through expo 10% of the time. Android production 5% of the time.

Whatā€™s funny is - during the morning hours - on android through custom app it works 100% of the time. This morning during my testing it worked from 7AM CST-10:50AM CST. I wish I was making that up.

If I find a solution I will update my thread and this thread here.

Thanks for this coding related informationā€¦!!!

Can i see more from you on this topic..???

I got really good information from this content.thanks for sharing.