transistorsoft / cordova-background-geolocation-lt

The most sophisticated background location-tracking & geofencing module with battery-conscious motion-detection intelligence for iOS and Android.
http://www.transistorsoft.com/shop/products/cordova-background-geolocation
Other
657 stars 277 forks source link

Background location detection fails when doesn't Allow All The Time in Location Permission #1391

Open Rajam0310 opened 1 year ago

Rajam0310 commented 1 year ago

Your Environment

Actual Behavior

Location is not detected while app is running in background even when we doesn't select "Allow All The Time" in location permission.

christocracy commented 1 year ago

With WhenInUse authorization, you must manually toggle the plugin into the "tracking" state while your app is in the foreground, like a Jogging App, where the user clicks a [Start Workout] button.

the method to manually toggle location-tracking ON is BackgroundGeolocation.changePace(true). See the api docs.

Apps cannot automatically trigger location tracking in the background with WhenInUse authorization, when the device is detected to be moving.

Rajam0310 commented 1 year ago

We are getting these kind of ANR error from firebase console while detecting background geo-location, and then user not able to receive push notifications from firebase.

Here is the error log from firebase console: [com.transistorsoft.locationmanager.notification.TSLocalNotification.build] [ANR triggered by thread waiting for a binder transaction]

ActivityThread$H.handleMessage Fatal Exception: android.app.RemoteServiceException Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{ba356a5 u0 mybundleId/com.transistorsoft.locationmanager.service.LocationRequestService}

christocracy commented 1 year ago

Context.startForegroundService() did not then call Service.startForeground():

This is a very common Android ANR. [Google it](https://www.google.com/search?q=Context.startForegroundService()+did+not+then+call+Service.startForeground()%3A&oq=Context.startForegroundService()+did+not+then+call+Service.startForeground()%3A&aqs=chrome..69i57j0i512j0i22i30l5.446j0j4&sourceid=chrome&ie=UTF-8).

An Android Foreground-service (which this plugin makes use of), must call .startForeground() within 5 seconds of your app launching. If your own app code (or one of your other plugins) does too much processing on the Main Thread (eg: loading records from a database, long-running http request, etc), this prevents the plugin's foreground-services from calling .startForeground() before 5 seconds elapses.

It's your responsibility to determine what in your app is taking too much time on the Main Thread, preventing the plugin from calling .startForeground() in time.

You can determine what is consuming time on the Main Thread by implementing Android StrictMode in the Cordova java app Application.onCreate method.

This is not an easy task to do in a Cordova app. It is much easier to do this sort of thing with Capacitor, React Native and Flutter.

christocracy commented 1 year ago

We are getting these kind of ANR error from firebase console while detecting background geo-location, and then user not able to receive push notifications from firebase

Yes, I answered your question about this above. Implement StrictMode in your app and observe StrictMode violations in adb logcat when your app boots.

github-actions[bot] commented 1 week ago

This issue is stale because it has been open for 30 days with no activity.