Closed rrrasti closed 4 months ago
How sure are you about this fix? The following is similar I believe. https://github.com/HaylLtd/cordova-background-geolocation-plugin/pull/99
At least I can say, that after code changes in this PR, my app (targeting Android 14) can receive location updates. Without these changes I get only aforementioned exceptions.
Issue #99 is related to Android 12 (we need to specify mutability of PendingIntent). This PR is for apps targeting Android 14 (see https://developer.android.com/about/versions/14/behavior-changes-14#safer-intents).
Solution in this PR is not ideal, just quick fix (see e. g. https://stackoverflow.com/a/77691101 - the behavior should be the same as up to Android 13). Better approach would be to use e.g. explicit intents instead of implicit ones.
Do you think you can implement the "better" solution?
I refactored code to use explicit intents instead of implicit ones.
Great, thanks! Can you confirm this code is working for previous versions? mainly Android 13 and maybe 12?
@rrrasti I want to release a version soon, any chance to get a feedback on the above questions?
Hi @HarelM, do you have any plans to release the new version with this correction?
I'm having problems with the plugin when compiling for Android SDK 34, and testing the code in this PR worked correctly
I need answers to the above questions (android 12, 13 and mutable flag) in order to merge this. Once merged I'll release a new version. If you can take a look at the above and answer I'll be happy to merge.
Hi @HarelM. I did 2 tests here on Android 14 (Physical) and Android 10 (Virtual):
1 - Compiled for SDK 34: Ok, capture working in the background 2 - Compiled for SDK 33: Ok, capture working in the background
My config: `{ // all activityType: ios ? 'Other' : 'OtherNavigation', locationProvider: BackgroundGeolocationLocationProvider.RAW_PROVIDER, desiredAccuracy: 10, stationaryRadius: ios ? 5 : 1, distanceFilter: ios ? 5 : 1, debug: false, stopOnTerminate: true,
startForeground: true,
interval: 300000, // 5 minutes
fastestInterval: 300000, // 5 minutes
activitiesInterval: 300000, // 5 minutes
notificationsEnabled: false,
// iOS
saveBatteryOnBackground: true,
};`
Do you need any more tests? And without these adjustments when compiling for SDK 34 the event to update the geolocation is not fired in the background
Ahh, I thought that there was a change around the mutable flags, but it was only a white space change... I'll push this forward within the next few days.
@HarelM Ok I will wait
I have released a new version, and tested it on my app only to see that the locations are not captured while the app is not topmost... :-( I'll need to investigate I guess if this fix works for you...
@HarelM
I tested it today with the new version and when leaving the application in the background, geolocations continued to be captured. I use sending requests with the capacitor http to continue being sent after 5 minutes
Which SDK target did you test?
My SDK target and compile is 34 and is required add this permission in AndroidManifest:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION"/>
I released a new version with foreground service location permission yesterday, which is working as expected on my physical device and on the emulator. But it didn't work without the above permission...
This solves the following error when targeting Android 14+:
java.lang.IllegalArgumentException: Targeting U+ (version 34 and above) disallows creating or retrieving a PendingIntent with FLAG_MUTABLE, an implicit Intent within and without FLAG_NO_CREATE and FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT for security reasons. To retrieve an already existing PendingIntent, use FLAG_NO_CREATE, however, to create a new PendingIntent with an implicit Intent use FLAG_IMMUTABLE.
This solves the following error when targeting Android 14+:
java.lang.SecurityException: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts