cordova-plugin-background-geolocation: App crashes on android 10 when use ACTIVITY_PROVIDER

Your Environment

  • Plugin version: 3.1.0
  • Platform: Android
  • OS version: 10
  • Device manufacturer and model: Honor 10 Lite.

Context

When call BackgroundGeolocation.start() app crashes

Expected Behavior

Start background geolocation.

Actual Behavior

App crashes

Possible Fix

https://developer.android.com/about/versions/10/privacy/changes#physical-activity-recognition

Steps to Reproduce

  1. Configuru background location with ACTIVITY_PROVIDER: BackgroundGeolocation.configure({locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER})
  2. Call BackgroundGeolocation.start()

Debug logs

08-18 11:28:22.384 6724 6724 E AndroidRuntime: FATAL EXCEPTION: main 08-18 11:28:22.384 6724 6724 E AndroidRuntime: Process: ru.okdesk.mobile, PID: 6724 08-18 11:28:22.384 6724 6724 E AndroidRuntime: java.lang.SecurityException: Activity detection usage requires the ACTIVITY_RECOGNITION permission 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at android.os.Parcel.createException(Parcel.java:2071) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:2039) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:1987) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.internal.zzed.zzb(Unknown Source:10) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.internal.zzccz.zza(Unknown Source:15) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.internal.zzcdi.zza(Unknown Source:26) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.internal.zzcbt.zza(Unknown Source:6) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.internal.zzbax.zzb(Unknown Source:0) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.internal.zzbbz.zze(Unknown Source:69) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.internal.zzbcw.zze(Unknown Source:5) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.internal.zzbco.zze(Unknown Source:152) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.internal.zzcbs.requestActivityUpdates(Unknown Source:9) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.marianhello.bgloc.provider.ActivityRecognitionLocationProvider.attachRecorder(ActivityRecognitionLocationProvider.java:151) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.marianhello.bgloc.provider.ActivityRecognitionLocationProvider.onConnected(ActivityRecognitionLocationProvider.java:175) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.common.internal.zzac.zzn(Unknown Source:109) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.internal.zzbco.zzm(Unknown Source:22) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.internal.zzbcc.zzpY(Unknown Source:89) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.internal.zzbcc.onConnected(Unknown Source:21) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.internal.zzbcw.onConnected(Unknown Source:7) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.internal.zzbbh.onConnected(Unknown Source:5) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.common.internal.zzaa.onConnected(Unknown Source:2) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.common.internal.zzn.zzrj(Unknown Source:152) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.common.internal.zze.zzs(Unknown Source:48) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.common.internal.zzi.zzrk(Unknown Source:57) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.google.android.gms.common.internal.zzh.handleMessage(Unknown Source:275) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:107) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at android.os.Looper.loop(Looper.java:213) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:8178) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) 08-18 11:28:22.384 6724 6724 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: FATAL EXCEPTION: mainjava.lang.SecurityException: Activity detection usage requires the ACTIVITY_RECOGNITION permission 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at android.os.Parcel.createException(Parcel.java:2071) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at android.os.Parcel.readException(Parcel.java:2039) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at android.os.Parcel.readException(Parcel.java:1987) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.internal.zzed.zzb(Unknown Source:10) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.internal.zzccz.zza(Unknown Source:15) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.internal.zzcdi.zza(Unknown Source:26) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.internal.zzcbt.zza(Unknown Source:6) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.internal.zzbax.zzb(Unknown Source:0) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.internal.zzbbz.zze(Unknown Source:69) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.internal.zzbcw.zze(Unknown Source:5) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.internal.zzbco.zze(Unknown Source:152) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.internal.zzcbs.requestActivityUpdates(Unknown Source:9) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.marianhello.bgloc.provider.ActivityRecognitionLocationProvider.attachRecorder(ActivityRecognitionLocationProvider.java:151) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.marianhello.bgloc.provider.ActivityRecognitionLocationProvider.onConnected(ActivityRecognitionLocationProvider.java:175) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.common.internal.zzac.zzn(Unknown Source:109) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.internal.zzbco.zzm(Unknown Source:22) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.internal.zzbcc.zzpY(Unknown Source:89) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.internal.zzbcc.onConnected(Unknown Source:21) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.internal.zzbcw.onConnected(Unknown Source:7) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.internal.zzbbh.onConnected(Unknown Source:5) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.common.internal.zzaa.onConnected(Unknown Source:2) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.common.internal.zzn.zzrj(Unknown Source:152) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.common.internal.zze.zzs(Unknown Source:48) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.common.internal.zzi.zzrk(Unknown Source:57) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.google.android.gms.common.internal.zzh.handleMessage(Unknown Source:275) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at android.os.Handler.dispatchMessage(Handler.java:107) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at android.os.Looper.loop(Looper.java:213) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at android.app.ActivityThread.main(ActivityThread.java:8178) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at java.lang.reflect.Method.invoke(Native Method) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) 08-18 11:28:22.387 6724 6724 E com.marianhello.logging.UncaughtExceptionLogger: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)

About this issue

Most upvoted comments

@bjdose hey man, sorry for delay. I created a fork here https://github.com/7h4r05/cordova-plugin-background-geolocation. Please let me know if it works for you.

Okay, I made it works… but BackgroundGeolocation.getCurrentLocation always returns the same value in background. It works well on foreground… and it does not send any requests to url or syncUrl as well…

Worked after added to Manifest following 2 strings and manually added permision at app settings… <uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" /> <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />

After I changed options it`s alived: stationaryRadius: 0, distanceFilter: 0,

Hi, Android 10 requires an ACTIVITY_RECOGNITION permission to be asked explicitly. The fix is to update the permissions in BackgroundGeolocationFacade & LocationManager from

public static final String[] PERMISSIONS = {
        Manifest.permission.ACCESS_COARSE_LOCATION,
        Manifest.permission.ACCESS_FINE_LOCATION
};

to

    public static final String[] PERMISSIONS = {
           Manifest.permission.ACCESS_COARSE_LOCATION,
           Manifest.permission.ACCESS_FINE_LOCATION,
           Manifest.permission.ACTIVITY_RECOGNITION
   };

also make sure it exists in AndroidManifest.xml under uses-permission

@mauron85 I tried to add branch with fix, but seems it’s prohibited. Can you review above changes? Fixed on my devices. Thanks

Note above will work for android >= 10, for android < 10 the permissions ACTIVITY_RECOGNITION should not be added

I had this problem. And I managed to solve it like this: installed the plugin https://github.com/NeoLSN/cordova-plugin-android-permissions#readme and make a request to use ACTIVITY_RECOGNITION.

let permissions = cordova.plugins.permissions permissions.requestPermission(permissions.ACTIVITY_RECOGNITION, function (status) { console.log('[Log]', status) }, function (error) { console.log('[Error]', error) })

This causes an additional request from the user and there is no error