Weird error with BACKGROUND location permissions.

  1. SDK Version: 43
  2. Platform: Android
  3. Library with errors: expo.permissions

I want to know if someone can clarify because i tried everything ( even downgrading again ) and still get the same error.

The error in particular happens when you invoke the following expo-location function:
requestBackgroundPermissionsAsync()

And the error it throws in console:
failed [Error: You need to add ACCESS_BACKGROUND_LOCATION to the AndroidManifest.]

I have this setup on my app.json android permissions:

“ACCESS_BACKGROUND_LOCATION”,
“FOREGROUND_SERVICE”,
“ACCESS_COARSE_LOCATION”,
“ACCESS_FINE_LOCATION”

So no idea what the hell is going on, seems like expo is not adding it to watever it needs to be added or it’s missing somehow?

Any idea would be really helpfull, this was working flawless ( almost ).
Thanks.

I want to add the following link, as this issue is being discussed also in github
so if any of you is facing the same issue you can follow up the progress.

https://github.com/expo/expo/issues/14774

Are we able to get background location while using the Expo app? The docs state we can, but I am unable to successfully request and get background location

Yes, as i’ve stated, it’s not working currently, i even tried on production apps, but i’m unable to get the required notification.

As per se, google is asking me now a video demostrating, not only how i ask for background permissions but also the functionality itself, pretty anoying.

I hope this gets resolved soon, as i’m unable to get it since updated to SDK43.

So, just for clarity, you were able to set up background permissions in your Expo App, but it’s no longer working, correct? I have been having trouble setting up background location permissions, even in my original version, which was built in SDK 40.

Yes, it was working on SDK 42, certainly i could ask for foreground and background permissions properly.

It’s strange that you’re having issues, mine it was working since i implemented it on sdk 38 but now after SDK43 just stoped working.

How did you do this with SDK 42? I’m running my app on managed workflow, and tried following the docs, but I can’t get it to work right :sweat_smile:

Can’t help you with that, i got the setup much before SDK42, it seems like the latest changes by google about background and foreground geolocation broke a bit the original workflow.

We must wait until they resolve this background issue with the cli to see how to fix it for good on the built app.

What does your current set up look like?

I have defined a background tasks like:

TaskManager.defineTask(LOCATION.TRACKING_KEY, async ({ data, error }) => {
 // do your logic here in my case i'm emmitting an event and storing data to localStorage.
 DeviceEventEmitter.emit("EMMIT_KEY", data );
});

And then i just have this to start location updates:

await Location.startLocationUpdatesAsync("TRACK_KEY", {
          accuracy: Location.Accuracy.BestForNavigation,
          activityType: Location.ActivityType.AutomotiveNavigation,
          enableHighAccuracy: true,
          timeInterval: 1000,
          // distanceInterval: 10, // minimum change (in meters) betweens updates
          // deferredUpdatesInterval: 3000, // minimum interval (in milliseconds) between updates
          // foregroundService is how you get the task to be updated as often as would be if the app was open
          foregroundService: {
            notificationTitle: I18n.t("fGNotificationTitle"),
            notificationBody: I18n.t("fGNotificationBody"),
            notificationColor: "#59abd6",
          },
          showsBackgroundLocationIndicator: true,
        });

When app comes from background it retrieves stored data, and vice-versa, because
when in background UI updates are not working, so what i do is store it in the background
tasks and then retrieve it and save to the context of the app.

Hope it helps.

I hadn’t dealt with TaskManager prior to dealing with Background Locations, so I currently have this set up by requesting the Foreground permissions in the first screen, “Screen A”, and then in the following screen (Screen B) I request for background permissions.

Do I keep the TaskManager in the same file I request permissions, or do I put it elsewhere?

Below is what I have:

Screen A’s (foreground) permission request looks like this:

 useFocusEffect(
  React.useCallback(()=>{
    let isActive = true
  
async function getLocationAsync(){
  let{status} = await Location.requestForegroundPermissionsAsync()
    if (status !== 'granted'){
     setErrorMsg('Permission to access location was denied')
 return;
}

   let location = await Location.getCurrentPositionAsync({})
     setLocation(location)
}

getLocationAsync()

   },
 [],
 ),
),

Screen B’s (background) permission request looks like this:

 useEffect(()=>{
    
      let isActive = true

const requestBackgroundPermissions = aync() =>{ //Requests permission
  const{status} = await Location.requestBackgroundPermissionsAsync()
    if (status === 'granted'){
     await Location.startLocationUpdateAsync(LOCATION_TASK_NAME,{
       accuracy: Location.Accuracy.Balanced
   })
 }
}


async function getBackgroundLocationAsync(){ //Gets Background Location
  let{status} = await Location.requestBackgroundPermissionsAsync()
    if (status !== 'granted'){
     setErrorMsg('Permission to access background location was denied')
 return;
}

   let backgroundLocation = await Location.getBackgroundPositionAsync({})
     setBackgroundLocation(backgroundLocation)
}

requestBackgroundPermissions()
getBackgroundLocationAsync()

  return()=>{
     isActive=false
  }

  },
 [],
)

TaskManager Setup

TaskManager.defineTask(LOCATION_TASK_NAME,({data, error})=>{
  if(error){
    return;
}
 if(data){
  const{locations}= data
 }
})

Any thoughts?

Sorry, i have no clue with what’s happening to you, i guess it’s just similar to my problem not being hable to get background location to work as expected…

Probably we should need to wait until SDK 44 to see if this problem is fixed.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.