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

Android 14 - Exif not being returned from the camera #916

Open
3 tasks done
JohnCastle4 opened this issue Oct 29, 2024 · 7 comments
Open
3 tasks done

Android 14 - Exif not being returned from the camera #916

JohnCastle4 opened this issue Oct 29, 2024 · 7 comments

Comments

@JohnCastle4
Copy link

Bug Report

Problem

What is expected to happen?

Exif data is returned - including geolocation

What does actually happen?

On Android 11 it works fine.
On Android 14, geolocation EXIF information is missing.

Information

Command or Code

Environment, Platform, Device

Galaxy Tab A for Android 11.
Galaxy Tab A9 for Android 14.

Version information

Cordova-Android : 13.0.0
Cordova-Camera_Plugin: 7.0.0

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@JohnCastle4
Copy link
Author

JohnCastle4 commented Oct 29, 2024

I have a suspicion that the Android OS has locked it down so the location permission can't be passed from the Cordova application to the camera. Can you confirm this is the case?
Exif location information even seems to be missing when picking from the gallery.

@breautek
Copy link
Contributor

Are you able to confirm if a particular image has location information in the exif by some other means? (Perhaps by pulling the image directly over ADB or over USB)

Normally the geolocation information is provided only if the underlying camera plugin adds it when the image was captured. The camera application itself would need the geolocation permissions granted for it to do this. Images in the gallery could also come from any source that may or may not have added geolocation information. So if the image itself lacks the geolocation exif data, then naturally it won't be available in cordova either.

When it comes to android changes, a good place to start is:

I haven't looked through them but if there are intended behaviour changes at the android SDK level, it should be noted in one of those links.

@JohnCastle4
Copy link
Author

Taking from the gallery I can confirm that when I copy the file locally from DCIM, the exif location information is present, but if I select the same picture from the gallery in the application the location information is not present when the camera launcher reads the EXIF. It is present on Android 11, but not Android 14.
So Camera is working fine on its own, it's processing through the camera plugin that isn't working.
I've been trying to pin down which Android change is affecting the location permissions and, it's not obvious to me.

@JohnCastle4
Copy link
Author

Reading more I believe it's due to this policy:
https://support.google.com/googleplay/android-developer/answer/13986130
Location permission is being tightened up. Our app has location permission, it's core functionality. The camera app has permission, it's optional functionality that's useful. I suspect that passing the permission between applications and sharing location information is now more difficult, but I've not dug into the details of the policy implementation.

@JohnCastle4
Copy link
Author

https://support.google.com/googleplay/android-developer/thread/304805154?hl=en&sjid=13835760325836208891-EU
I raised a ticket on Google, their reply:
To address the missing EXIF location tags on Android 14 (API 34), try the following steps:

  • Check Permissions: Ensure that your app has the ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions in your manifest and that they are granted at runtime.
  • Add Location to Intent: When launching the camera intent, explicitly set the location. You can use the ExifInterface to manually add the location tags to the image after capturing it.
  • Use MediaStore API: If you're saving the image to a specific location, make sure to include the location metadata when inserting the image into the MediaStore.
  • Review Camera Implementation: If you're using a custom camera implementation, ensure that it’s configured to include location metadata in the EXIF data.
  • Check for Known Issues: Look into any known issues or changes in behavior with the camera API in the Android 14 documentation or forums.
    By following these steps, you should be able to ensure that location tags are properly included in the EXIF data for photos taken with your app.

First step is true, we have both permissions. Not quite sure what the implications of the remaining steps are.

@JohnCastle4
Copy link
Author

This is a significant issue for our application. Photos are used by our users for two purposes, audit trail to prove the work they did in the field (before and after photos while time and location stamps), also for logging the condition which can be important for insurance claims, being able to prove it was taking at the location on the specific date is again important.

We have photo watermarking capability which can cover this requirement, but we've always relied on being able to fall back on the exif metadata.

  • Check Permissions: Ensure that your app has the ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions in your manifest and that they are granted at runtime.
    We definitely have these permissions.

  • Add Location to Intent: When launching the camera intent, explicitly set the location. You can use the ExifInterface to manually add the location tags to the image after capturing it.
    The latter part of these, we could figure temporarily, but we couldn't share the result back due to our company's open source policies.
    The first part implies that location can be passed through the camera intent. I'm going to check how that's done, because if that's all that's needed that would be ideal.

  • Use MediaStore API: If you're saving the image to a specific location, make sure to include the location metadata when inserting the image into the MediaStore.
    I believe we already have issues with the gallery copy and exif, to be honest as long as the image returned from the camera has the exif metadata our application is working acceptably.

  1. Review Camera Implementation: If you're using a custom camera implementation, ensure that it’s configured to include location metadata in the EXIF data.
    I don't believe it possible for Cordova to use a custom camera on Android any more, this is why we added the watermark since our customers were previously using a custom camera with watermarking.
  • Check for Known Issues: Look into any known issues or changes in behavior with the camera API in the Android 14 documentation or forums.
    I think we've understood why the issue is occurring and we're looking for a fix now.

I was wondering if you were able to verify the issue, we're concerned about this loss of functionality and finding a fix is going to become important quickly.

@breautek
Copy link
Contributor

breautek commented Nov 4, 2024

Add Location to Intent: When launching the camera intent, explicitly set the location. You can use the ExifInterface to manually add the location tags to the image after capturing it.

I believe this is how the iOS implementation kind of works, but it involves an additional level of complexity as it requires managing location state with another asynchronous process. I think it was necessary for iOS whereas Android, the underlying camera application typically handled it assuming the Camera application itself had the geolocation permissions.

To make the geolocation permissions optional, iOS uses a preference, and when enabled it will request and use the geolocation APIs and add to the exif itself. Android could do the same thing, and use the same preference to enable the functionality.

The core location API available in Android is not great to say the least, and documentation is sparse. They have a Google Play services API for geolocation instead, but making the camera plugin depend on that will likely be considered a breaking change.

Before we get into that though, I would like to see why the EXIF attributes are not being returned in the first place, given you said that they are actually available if you pull directly from DCIM and inspect the metadata manually.

I don't believe it possible for Cordova to use a custom camera on Android any more, this is why we added the watermark since our customers were previously using a custom camera with watermarking.

Cordova never implemented a custom camera, or uses the camera APIs directly. It always relied on using Intents, which is a way for one application to delegate camera tasks to another installed application (which the user may choose) and have the result be given back to the requesting application.

It is possible that the installed Camera application being used just doesn't use geolocation or set the location EXIF attributes anymore when capturing photos. But I think you've cleared that possibility in this case by stating:

Taking from the gallery I can confirm that when I copy the file locally from DCIM, the exif location information is present, but if I select the same picture from the gallery in the application the location information is not present when the camera launcher reads the EXIF.

If the underlying image contains the EXIF attributes, then at least sourcing that same image by picking from the gallery

I don't believe it possible for Cordova to use a custom camera on Android any more, this is why we added the watermark since our customers were previously using a custom camera with watermarking.

Is it possible that your watermarking tool is messing with EXIF attributes? Are you able to reproduce the issue in a Sample Reproduction app? If so then that sample project can be shared which will help serve as a test case.

I was wondering if you were able to verify the issue, we're concerned about this loss of functionality and finding a fix is going to become important quickly.

I have not and I haven't had an opportunity to try to replicate the issue either. To be frank my volunteer time is better spent elsewhere to solve the problems with using READ_MEDIA_* permissions which affects a larger user base of developing Cordova applications currently. So I don't foresee myself getting much deeper in the near future than the support I'm currently attempting to provide. I don't mean any disrespect, so I apologise if it's coming across this way.

I'm sharing knowledge in hopes that it can provide enough assistance for you/your company to find the root cause and potential solutions, especially since at the moment you have a reproduction case available to test against. And if you do find the cause and solution, then it would be nice (but not required to) send a pull request back to the Camera plugin under the Apache 2.0 license. If your company forbids it, then your company will likely require to fork and maintain their own version of the camera plugin instead of relying on open source contributions, especially if a fix for this feature is mission critical for your app.

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

No branches or pull requests

2 participants