Feature/android background permission #149
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 existingopenSettingsIfLocationHasBeenDenied
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".