transistorsoft / capacitor-background-geolocation

The most sophisticated background location-tracking & geofencing module with battery-conscious motion-detection intelligence for iOS and Android.
MIT License
96 stars 16 forks source link

Different behaviour between Android devices #60

Closed drtomato closed 2 years ago

drtomato commented 2 years ago

Your Environment

Latest Dependencies:

@capacitor/cli: 3.4.3 @capacitor/core: 3.4.3 @capacitor/android: 3.4.3 @capacitor/ios: 3.4.3

Installed Dependencies:

@capacitor/cli: 3.1.1 @capacitor/core: 3.1.1 @capacitor/android: 3.1.1 @capacitor/ios: 3.1.1

[success] iOS looking great! πŸ‘Œ [success] Android looking great! πŸ‘Œ

Expected Behavior

onLocation should be called with new locations when moving

Actual Behavior

onLocation is not called (see full description below)

Context

I am using the plugin successfully on iOS with a map-based app that I am developing (Ionic/Angular/Capacitor). Now I am migrating to Android (which is a new experience to me, I am not 100% familiar with all the tools yet) and have a few questions. I am currently testing on the Pixel 4 (API 30, Android 11) and Pixel 5 (API 31, Android 12) emulators in Android Studio and on three physical devices; a Samsung Galaxy S10e (API 31, Android 12), a Samsung Galaxy S4 (originally Android 5, upgraded to the LineageOS ROM (API 30, Android 11)) and an Alcatel 1 2021 (Android 11 Go).

The Galaxy S10e works fine, similar to the iOS versions I have tested on, but the two others fail:

The Alcatel 1 is a really low-end device and is running a sneak Android version called Android 11 Go. Here I only get the current location the first time. After that, I never get onLocation updates and therefore my current location on the map never changes no matter how far I move. The exception is when a geofence is triggered, then the current location is updated to the triggering location. Google Map has no problem showing my location continuously so I guess there is nothing wrong with the device itself. But the exact same code that works on iOS and on the S10e does not work on this device and I would like to understand why. I believe that the device has accelerometers and other sensors (but who knows, it was the cheapest Android phone I could find…) but maybe the problem is that the plugin, for whatever reason, does not detect changes in movement? From the logs it appears that the plugin is loaded and initiated properly. My question is whether it has been confirmed that the plugin works on Android 11 Go?

The S4 is too old to run my app with its original Android version, which is why I upgraded it to a custom ROM Android 11 version called LineageOS. My device may not be fully supported (or I failed to configure it properly) since I get an error dialog saying that Google Play services are not supported on the device ()but only when I run my app, all other apps work). This error seems to be picked up by the BackgroundGeolocation plugin (error code 408). My question is whether Google Play services are actually necessary for the plugin to work? My attempts to fix the Google Play services error have failed sofar and I know that other people have had similar problems with other apps that refuse to run for the same reason.

P.S. I am experimenting with the 'disableMotionActivityUpdates' setting now. Back with more info later...

P.P.S. I have installed the Cordova BG Geolocation demo on the devices. This should help me understand the plugin's behavior better with regard to the different settings. I will post relevant info here later.

Debug logs

Logs ``` PASTE_YOUR_LOGS_HERE ```
christocracy commented 2 years ago

My question is whether it has been confirmed that the plugin works on Android 11 Go?

I don't know anything about Android 11 Go. This plugin is developed according to published Android documentation and relies upon APIs provided by Google Play Services, particularly the Fused Location Provider API and Activity Recognition API.

My question is whether Google Play services are actually necessary for the plugin to work?

Yes.

P.S. I am experimenting with the 'disableMotionActivityUpdates' setting now.

The plugin uses a "stationary geofence" as a fallback for detecting when device is moving when Motion API is disabled. This requires the device move about 200 meters before location-tracking is engaged. Geofence triggering in the Android emulator often does not work.

christocracy commented 2 years ago

Also see https://dontkillmyapp.com for tracking problems with particular Android devices.

drtomato commented 2 years ago

Thanks Chris!

drtomato commented 2 years ago

OK, I solved the problem. I attach info here in the hope that it might be useful to someone else: