Cordova-plugin-background-geolocation: Foreground service doesn't work in Android 10

Created on 16 Apr 2020  Â·  13Comments  Â·  Source: mauron85/cordova-plugin-background-geolocation

Hi,

In Android 10 the service definition in the manifest file must have: android:foregroundServiceType="location" in order for the foreground service to work properly (ie. when user select "only while using app" as location permission.

<service android:enabled="true" android:exported="false" android:foregroundServiceType="location" android:name="com.marianhello.bgloc.service.LocationServiceImpl" />

I hope it is possible to add this in the next version.

Does anyone have a quick fix for this? My current solution is to add the line manually to the manifest file after each "cordova prepare". It is just a matter of time before I forget it before releasing.

Most helpful comment

To be honest, this (discontinued) plugin and all (I guess - don't know all) forks are dying due to the lack of adjustments to the latest SDKs and other evolution.
There have been a lot of changes in Android 10 + 11 regarding the background (always) permission and capability of sending position updates in the background. Also iOS 14 introduced the approximate location.
Additionally many major vendors kill apps in the background, see https://dontkillmyapp.com/
So this plugin should actually be renamed to cordova-plugin-foreground-geolocation. ;-)
Only the original (paid) plugin seems to keep track of the plugin to work in the background/minimized: https://github.com/transistorsoft/cordova-background-geolocation-lt

All 13 comments

I had this same issue and just added this to the config.xml file (within the platform name=android section)

    <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/uses-permission" xmlns:android="http://schemas.android.com/apk/res/android">
        <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    </edit-config>

I added this to my config.xml and 'android:foregroundServiceType="location"' still doesn't appear on my service tag.

You may want to run prepare and make sure it regenerates the file, if that still doesnt work, send me the full config file and I will see if anything jumps out that could be causing it to not work.

config.txt

It didn't work, here is my config.xml , thank you!

Not sure why its not working - Im assuming you removed the current file just to make sure it recreated a new one? Other than that the file path is the only difference I see - but if your others are working then I would presume this one should to. Just to rule it out, you may want to use what I have exactly - filename and the XMLNS:android (I know you have it in the header - but again - just to rule it out.

Good luck.

When you say remove the current file, do you mean '~platforms\android\app\src\mainAndroidManifest.xml'? I removed that and ran prepare and it did not recreate it, it errored out trying to find it.

Anyone got this working?

I did... Had no issues. What problem are you seeing?

On Thu, Jun 18, 2020, 10:46 PM Marc notifications@github.com wrote:

Anyone got this working?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/mauron85/cordova-plugin-background-geolocation/issues/691#issuecomment-646404221,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ADVCHDVVJMGK7PJE63X6SIDRXLGOPANCNFSM4MJWCR2A
.

Hi guys,
as Android SDK 29 is mandatory till November 2, 2020 this is a quite urgent issue to keep this plugin alive.

I made the geoposition updates work in background (without ALWAYS permission) with these adjustments:
Angular:

this.backgroundGeolocation.configure({
    startForeground: true,
    activityType: "AutomotiveNavigation",
    saveBatteryOnBackground: false
});

AndroidManifest.xml:

<service android:enabled="true" android:exported="false" android:foregroundServiceType="location|dataSync" android:name="com.marianhello.bgloc.service.LocationServiceImpl" />
<service android:exported="true" android:foregroundServiceType="location|dataSync" android:name="com.marianhello.bgloc.sync.SyncService" android:process=":sync">
    <intent-filter>
        <action android:name="android.content.SyncAdapter" />
    </intent-filter>
    <meta-data android:name="android.content.SyncAdapter" android:resource="@xml/syncadapter" />
</service>
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />

If you do that manually android.json must be adjusted the same way.
It would be best to adjust the plugin accordingly so the correct permissions are automatically rendered in all corresponding config files.

Can somebody make it work on Android 10 without ALWAYS permission?

Can somebody make it work on Android 10 without ALWAYS permission?

I used this fork of this same plugin:
cordova plugin add https://github.com/Astroxslurg/cordova-plugin-background-geolocation.git

That has all the necesary changes on manifest that makes this plugin work on foreground.
Works like a charm, try it out.
Dont know why the oficial repository does not have this necessary changes though.

To be honest, this (discontinued) plugin and all (I guess - don't know all) forks are dying due to the lack of adjustments to the latest SDKs and other evolution.
There have been a lot of changes in Android 10 + 11 regarding the background (always) permission and capability of sending position updates in the background. Also iOS 14 introduced the approximate location.
Additionally many major vendors kill apps in the background, see https://dontkillmyapp.com/
So this plugin should actually be renamed to cordova-plugin-foreground-geolocation. ;-)
Only the original (paid) plugin seems to keep track of the plugin to work in the background/minimized: https://github.com/transistorsoft/cordova-background-geolocation-lt

To be honest, this (discontinued) plugin and all (I guess - don't know all) forks are dying due to the lack of adjustments to the latest SDKs and other evolution.
There have been a lot of changes in Android 10 + 11 regarding the background (always) permission and capability of sending position updates in the background. Also iOS 14 introduced the approximate location.
Additionally many major vendors kill apps in the background, see https://dontkillmyapp.com/
So this plugin should actually be renamed to cordova-plugin-foreground-geolocation. ;-)
Only the original (paid) plugin seems to keep track of the plugin to work in the background/minimized: https://github.com/transistorsoft/cordova-background-geolocation-lt

That is true, actually Im starting to train myself in Flutter because all of this issues with cordova.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vlafranca picture vlafranca  Â·  6Comments

Shakti-Sharma picture Shakti-Sharma  Â·  3Comments

mauron85 picture mauron85  Â·  4Comments

anusree-mmlab picture anusree-mmlab  Â·  5Comments

sasiadstar picture sasiadstar  Â·  4Comments