HaylLtd / cordova-background-geolocation-plugin

Background and foreground geolocation plugin for Cordova.
Apache License 2.0
53 stars 63 forks source link

POST_NOTIFICATIONS permission on Android 13+ #186

Closed flyonthenet closed 1 week ago

flyonthenet commented 3 weeks ago

Describe the bug No persistent banner is displayed in notification tray when you start background geolocation on Android 13/14 devices Notification options are grayed out in app settings

Seems that POST_NOTIFICATIONS permission is required to display persistent notification banner https://developer.android.com/develop/ui/views/notifications/notification-permission On previous Andriod versions works fine (tested on Android 7/8)

I've added this line on my config.xml and notification banner came back:

<config-file target="AndroidManifest.xml" mode="merge" parent="/manifest">
            <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
</config-file>

To Reproduce

  1. Install APK on any Android 13+ devices
  2. Start Background geolocation

Expected behavior Persistent banner should displayed for privacy reasons

Smartphone (please complete the following information):

Additional context

I've added also the ACTIVITY_RECOGNITION permission on my APK Do you confirm that with this permission the background geolocation works anyway without notification banner with same precision?

Thanks in advance D.

HarelM commented 3 weeks ago

I'm not sure this is the root cause. I think there's a need to define the notification as ongoing: https://developer.android.com/training/wearables/notifications/ongoing-activity

Having said that, it might be better to introduce a flag to specify if notification should be enabled or not.

Feel free to submit a PR.

HarelM commented 1 week ago

I've tested with ongoing and it doesn't solve the issue, only adding push notification. I'll open a PR shortly.

HarelM commented 1 week ago

@flyonthenet you needed to request runtime permissions for post notification as well, right?

flyonthenet commented 1 week ago

@HarelM I had to grant permissions in phone settings. My app didn't ask permission at runtime, but it was previously installed with different SDK target, so this could be the cause. I didn't test a clean APK install.

HarelM commented 1 week ago

Ok, I'll be merging a PR that add this permission request at runtime and manifest and release a new version. Thanks for the input!