Geolocation in background (Ionic Angular Capacitor)

I have Ionic Angular app and I need location every 30s no matter if the app is in the foreground or the background. I have @capacitor/geolocation connected and it gives back location just fine while the app is in the foreground, but whenever it goes to the background I get no location back.

I’ve added android.permission.ACCESS_BACKGROUND_LOCATION along android.permission.ACCESS_COARSE_LOCATION android.permission.ACCESS_FINE_LOCATION in Android Manifest but still when I use Geolocation request permissions in the dialog I can give permissions for While I’m using the app and not always.

I also tried with capacitor-community/background-geolocation plugin which also works in the foreground but in background I got notification Location not available.

I’m testing on Pixel6 with the app running on phone from Android Studio and checking Run logs there.

Any help is appreciated!

I have had similar issues, let me know if you ever find a fix, good luck!

So, after going into app info and manually setting up location permissions to Allow always, it starts to work and I’m getting locations.

The other problem was with http throttling which didn’t let my app push once the app is in the background, there is a good explanation here which uses native http plugin instead of angular/http and now it works good.

So the only problem I’m having at the moment is that users have to go inside app info to actually set the permissions. I don’t like this approach but so far I haven’t find a solution for it. About that same problem I found an issue here in the background geolocation plugin and I’ve added additional comments, but still waiting on a response or fix.

I tried both libraries @capacitor/geolocation and capacitor-community/background-geolocation and both have the same problem with the permissions.

This plugin works fine Android notification · Issue #75 · HaylLtd/cordova-background-geolocation-plugin · GitHub