Fix API issues stemming from Android 13/14 changes to location services #210
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.
What was the problem
On newer Android 13 and 14 Devices, the startLocationService() function causes a fatal crash, causing the app to exit and show the error mentioned in #200.
How was it fixed
In the linked issue is a fork that already adresses 1 one of the issues caused by the version change, namely the extra flag for the reicever exported status, but it has some other issues that arise from Android 13 as well.
I fixed the
registerReceiver
call by making a API level check and depending on version code, call the function with or without the flag, in order to still stay compatible with API level 26 and below where the flag does not exist, inspired by this StackOverflow answer.There was also another issue, caused be new permission requirements for the foreground service, where now need to more precisely define what kind of foreground service it is, which I added to the manifest.
We also need to again change the function call signature of the foreground service to add the new permission type based on API level as before, inspired by this StackOverflow answer.