Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/android background permission #149

Merged

Conversation

siewedu
Copy link
Contributor

@siewedu siewedu commented Jul 29, 2021

ACCESS_BACKGROUND_LOCATION has been introduced with Android SDK API level 29 which is required in order to access the location while the app is in background. (https://developer.android.com/training/location/permissions). Currently there is no way to request for background location with this plugin. I added the always option which already exists on the iOS API also to the Android API, which can be used to request the background location. I also added the already existing openSettingsIfLocationHasBeenDenied option to the Android API so the user will be taken to the settings in case the user has previously denied location permission.

Unfortunately the openSettingsIfLocationHasBeenDenied option was kind of broken with the introduction of the 'one time' permission in Android 11 (API Level 30). It is practically impossible to differentiate between the case where user has given a 'one time' permission and the case where the 'don't ask again' option was selected. For a detailed explanation see here or here.

This forces us to handle both cases in the same way. I chose to try to request the permission in both cases which ensures that the system permission prompt is always presented again to the user if he gave a 'one time' permission. On the other hand it means that the user won't be taken to the settings on Android 11 after he denied the permission twice during the installation lifetime of the app, even if the openSettingsIfLocationHasBeenDenied option is true.
https://developer.android.com/training/permissions/requesting#one-time
But this seems to be the preferred way according to the Android guidelines which state specifically "to not link to system
settings in an effort to convince the user to change their decision".

Eduard added 3 commits July 27, 2021 12:47
…troduced with SDK v29. Added 'always' and 'openSettingsIfLocationHasBeenDenied' also to Android implementation, so that API is now the same as on iOS.
@cla-bot cla-bot bot added the cla: yes label Jul 29, 2021
@NathanWalker
Copy link
Contributor

This is awesome @siewedu thank you. Lemme see if @triniwiz can help review this.

Copy link
Member

@triniwiz triniwiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@NathanWalker NathanWalker merged commit 00be346 into NativeScript:master Aug 11, 2021
@NathanWalker
Copy link
Contributor

@siewedu this is published with 7.2.0 - we bumped the minor just in case it affected any projects using ~ at moment.
Thanks again!

@siewedu
Copy link
Contributor Author

siewedu commented Aug 16, 2021

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants