capacitor-community / background-geolocation

A Capacitor plugin that sends you geolocation updates, even while the app is in the background.
MIT License
187 stars 57 forks source link

Check background location permission #103

Closed jongbonga closed 1 year ago

jongbonga commented 1 year ago

Is your feature request related to a problem? Please describe. Currently, with the capacitor Geolocation plugin, we can check for permission status but it does not provide status for background location. especially for Android.

This is from Sentry Diagnostics.

Screenshot 2023-06-28 at 16 44 16

Describe the solution you'd like Can this plugin offer a way to check which permission is granted (coarse, fine or background)?

alexandermccormick commented 1 year ago

Just my two cents, but I believe you can use the Capacitor Permissions plugin to check which permissions have been granted.

As far as I know, this plugin doesn't use the ACCESS_BACKGROUND_LOCATION permission, but instead utilizes a foreground service. This is why there is a persistant notification. The ACCESS_BACKGROUND_LOCATION permission is a bit more intense, and requires you to send in a video explaining and demonstrating exactly how you use that permission.

diachedelic commented 1 year ago

That is correct. Don't worry about the background permission.

jongbonga commented 1 year ago

@alexandermccormick I did send a video demonstrating the use, but my user still experience issue tracking the location when the driver is an Android user, and I keep seeing the above issue on Sentry.

and my options on the app look like

{
  backgroundTitle: 'My App is tracking your trip.',
  backgroundMessage: 'My App is operating on the background.',
  distanceFilter: prodMode ? 2 : 0
}

So not sure how to handle it.

diachedelic commented 1 year ago

Some Android devices need battery saving optimizations disabled (via the Settings app) to reliably receive location updates in the background. Your Sentry report mentioning ACCESS_BACKGROUND_LOCATION is a red herring - this plugin does not need that permission.

diachedelic commented 1 year ago

What problem is your user experiencing exactly?

jongbonga commented 1 year ago

Your Sentry report mentioning ACCESS_BACKGROUND_LOCATION is a red herring - this plugin does not need that permission.

I added it since I thought that was the reason I wasn't getting constant updates.

What problem is your user experiencing exactly?

Screenshot 2023-07-09 at 14 39 55

The location is not being received or sent after a while. I will remove ACCESS_BACKGROUND_LOCATION and try again and revert when I get updates

diachedelic commented 1 year ago

Make sure you are using the legacy bridge, otherwise location updates will stop after 5 minutes in the background on Android. https://github.com/capacitor-community/background-geolocation#android

jongbonga commented 1 year ago

Make sure you are using the legacy bridge, otherwise location updates will stop after 5 minutes in the background on Android. https://github.com/capacitor-community/background-geolocation#android

Screenshot 2023-07-10 at 11 03 43
diachedelic commented 1 year ago

Are you familiar with the limitations on sending HTTP requests while the app is in the background? See https://github.com/capacitor-community/background-geolocation/issues/14#issuecomment-1293574693.

jongbonga commented 1 year ago

Are you familiar with the limitations on sending HTTP requests while the app is in the background? See #14 (comment).

Yes, I use the capacitor http plugin. I'm busy testing with different devices to see if the issue is not our my server instead.

I will update asap.

jongbonga commented 1 year ago

Here are my findings:

  1. The location data get sent for a while then "pause" until I open the app again only to receive a bunch of them at once
  2. The notification shows but looks like it's the system notification and not the plugin's. I concluded so because the title & message are different from the one displayed. The title displayed says: AppName is running & the message: Tap for more information or to stop the app.

My plugin:

Screenshot 2023-07-10 at 19 37 48

My permissions

Screenshot 2023-07-10 at 19 42 24

My Capacitor config

Screenshot 2023-07-10 at 19 43 40

strings.xml

Screenshot 2023-07-10 at 19 47 36

Is there anything I could have missed?

diachedelic commented 1 year ago

I would say your problem is the notification. If the notification is not correctly configured, background location updates don't work properly. Make sure you've generated the icon correctly, using Android Studio:

    <!--
        The icon to use for the background notification. Note the absence of a
        leading "@". It defaults to "mipmap/ic_launcher", the app's launch icon.

        If a raster image is used to generate the icon (as opposed to a vector
        image), it must have a transparent background. To make sure your image
        is compatible, select "Notification Icons" as the Icon Type when
        creating the image asset in Android Studio.
    -->
    <string name="capacitor_background_geolocation_notification_icon">
        drawable/ic_tracking
    </string>

If the notification is misconfigured, it seems to open the Settings app when tapped, rather than your app.

jongbonga commented 1 year ago

Make sure you've generated the icon correctly, using Android Studio

Let me try this. My icons are generated with the capacitor assets plugin

jongbonga commented 1 year ago

They were all there already.

Screenshot 2023-07-11 at 11 20 55

I will run and see if the notification appears after this.

jongbonga commented 1 year ago

I got the notification working.

I did this.

To make sure your image is compatible, select "Notification Icons" as the Icon Type when creating the image asset in Android Studio.

My mistake was the name of the icon that I did not set properly. I kept the one from the example: ic_tracking.

I will revert later if I encounter issues.

Thanks for your patience and assistance.

diachedelic commented 1 year ago

No worries, glad you got it working.