react-native-background-geolocation
react-native-background-geolocation copied to clipboard
Android 13 - Notification permission requested on boot
After adding the react-native-background-geolocation
package to our project, the user has to grant permission on boot. You don't have to call any functionality, just installing the package is enough to encounter this issue.
Your Environment
- Plugin version: 4.8.2
- Platform: Android
- OS version: 13
- Device manufacturer / model: Google Pixel 6a
- React Native version: 0.64.2
- Plugin config: Not important, installing library is enough to encounter this issue
Expected Behavior
When booting an application on Android 13 that has react-native-background-geolocation
installed, users will see the native notification permission request. In our code, no interaction with any RN Background Geolocation-functionality is done. It should not be requested on boot without any RN Background Geolocation-interaction.
Actual Behavior
The library should not request notification permission
Steps to Reproduce
- Add the library to your project
- Boot the app
- (Eventually, kill and boot again)
- Notification permission is requested
I have not yet tested in Android 13
This is a UX-blocker for us in production, it's not the way we want to request permissions from our users. Is it possible to get yourself an Android 13 device and test/reproduce/fix this issue?
I’ll be installing Android 13 soon.
After a fresh install of Android 13 on my Pixel 6, I don’t notice anything unusual and the demo app operates exactly as before.
I will try now with a fresh install of demo app.
After fresh install of demo app on Android 13, terminate app, reboot app: I don't see anything about a "Notification permission requested".
I'm using:
compileSdkVersion = 33
targetSdkVersion = 33
I did a fresh install of the app from the Play Store and the first thing I see is: Notification permission request.
It's in Dutch, but it's really strange that you don't see the notification popup.
https://user-images.githubusercontent.com/10380088/187535210-997861d0-bcce-4aed-9572-f55e5f11e4ec.mp4
Create for me simple Hello World app which reproduces this for me. Share it in a public GitHub repo.
Followed the setup instructions to add the library to a clean project. Same behavior happens after a restart of the app.
I do not have access to the codebase of the internal library, but I think that (for debugging purposes) a NotificationChannel might be created on boot?
https://developer.android.com/develop/ui/views/notifications/notification-permission
If your app targets 12L (API level 32) or lower, the system shows the permission dialog the first time your app starts an activity after you create a notification channel, or when your app starts an activity and then creates its first notification channel. This is usually on app startup.
When setting compileSdkVersion
and targetSdkVersion
to 33, the problem is indeed resolved.
https://user-images.githubusercontent.com/10380088/187632169-7a18b8ab-44bf-4c24-b6ce-565010d3dc12.mp4
When setting compileSdkVersion and targetSdkVersion to 33, the problem is indeed resolved.
Correct. This is what you have to do. See Notification Permission Exemptions:

I am using targetSdkVersion 33 / compileSdkVersion 33
locally here. This is why I didn't see the runtime permission. When I downgrade to targetSdkVersion 31
, I do experience the behaviour you describe.
In my opinion, it still needs a fix. react-native-background-geolocation
should not ask for notification permissions because these are only used for debugging purposes. Everyone who's using this package and has not updated their targetSdkVersion
or compileSdkVersion
will have to deal with the notification permission package.
It might be useful to create the notification channels only when debugging is on. Otherwise, everyone will have a notification channel for debugging this library, even end-users who will never see notifications from react-native-background-geolocation
.
should not ask for notification permissions because these are only used for debugging purposes
No. This is not for debugging purposes, at all. This is the Required Persistent Notification for Foreground Services.

The Android plugin does not use notifications for debugging.
It should not request the permission before a config
or init
of the library is called. The fact that this library can cause a permission request on boot is unwanted.
It's wrong in the first place for Android 13 to request notification run-time permission for foreground-services — targetSdkVersion 33
fixes that wrong.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.