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

Fixed onCreate issue Android 14 #178

Merged
merged 5 commits into from
May 28, 2024
Merged

Fixed onCreate issue Android 14 #178

merged 5 commits into from
May 28, 2024

Conversation

rrrasti
Copy link

@rrrasti rrrasti commented Feb 20, 2024

  1. Added PendingIntent.FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT for PendingIntent objects created in DistanceFilterLocationProvider and ActivityRecognitionLocationProvider.

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.

  1. Added RECEIVER_NOT_EXPORTED to registerReceiver.

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

@HarelM
Copy link
Collaborator

HarelM commented Feb 20, 2024

How sure are you about this fix?
The following is similar I believe.
#99

@rrrasti
Copy link
Author

rrrasti commented Feb 22, 2024

@HarelM
Copy link
Collaborator

HarelM commented Feb 24, 2024

Do you think you can implement the "better" solution?

@rrrasti
Copy link
Author

rrrasti commented Feb 27, 2024

I refactored code to use explicit intents instead of implicit ones.

@HarelM
Copy link
Collaborator

HarelM commented Feb 28, 2024

Great, thanks!
Can you confirm this code is working for previous versions? mainly Android 13 and maybe 12?

@HarelM
Copy link
Collaborator

HarelM commented May 22, 2024

@rrrasti I want to release a version soon, any chance to get a feedback on the above questions?

@brunochikuji
Copy link

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

@HarelM
Copy link
Collaborator

HarelM commented May 28, 2024

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.

@brunochikuji
Copy link

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

@HarelM
Copy link
Collaborator

HarelM commented May 28, 2024

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.

@brunochikuji
Copy link

@HarelM Ok I will wait

@HarelM HarelM merged commit 730d716 into HaylLtd:stable May 28, 2024
1 check passed
@HarelM
Copy link
Collaborator

HarelM commented May 29, 2024

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...

@brunochikuji
Copy link

brunochikuji commented May 29, 2024

@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"/>

@HarelM
Copy link
Collaborator

HarelM commented May 30, 2024

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...

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

Successfully merging this pull request may close these issues.

4 participants