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

EXIF location metadata is removed from image when selected via ACTION_PICK #218

Open
6 of 7 tasks
fabalexsie opened this issue Apr 30, 2024 · 3 comments
Open
6 of 7 tasks
Labels
feature request Issue is about a new feature in the app

Comments

@fabalexsie
Copy link

fabalexsie commented Apr 30, 2024

Checklist

  • I made sure that there are no existing issues - open or closed - to which I could contribute my information.
  • I made sure that there are no existing discussions - open or closed - to which I could contribute my information.
  • I have read the FAQs inside the app (Menu -> About -> FAQs) and my problem isn't listed.
  • I have taken the time to fill in all the required details. I understand that the bug report will be dismissed otherwise.
  • This issue contains only one feature request.
  • I have read and understood the contribution guidelines.
  • I optionally donated to support the Fossify mission.

Feature description

If a third party application wants to retrieve an image and you decide to use this app for selecting, the location metadata should not be deleted and should also be made available to the third party application.

This is the android file selection dialog from which you can select this Gallery app ("Galerie").
file selection dialog to choose an app

Why do you want this feature?

My specific scenario:
I want to upload some of my pictures to my nextcloud and see them on a map.
I've used the android app Memories to upload some photos.
The selection process there is done via an ACTION_PICK Intent (i guess) which opens the native file selection dialog of android.
There i choose this gallery app and select some pictures.
When the pictures are returned to the Memories app, the location metadata field is empty. So I can't use this data in my nextcloud.

General use case
Selecting the image from another app for example for uploading or sharing it, should also share the location metadata and should not modify the file.

Additional information

I've also analysed it for my specific scenario and written a small fix.

I've tested it with the Memories app and I've written a small app myself that "asks" for an image via the Intent.ACTION_PICK and reads the location from the EXIF in the result. For both of them, this works.
I could fix the problem by copying the file to a cache folder and providing the public uri of that cached file instead of the original.

diff --git a/app/src/main/kotlin/org/fossify/gallery/activities/MainActivity.kt b/app/src/main/kotlin/org/fossify/gallery/activities/MainActivity.kt
index 834453471..e73d065ab 100644
--- a/app/src/main/kotlin/org/fossify/gallery/activities/MainActivity.kt
+++ b/app/src/main/kotlin/org/fossify/gallery/activities/MainActivity.kt
@@ -880,9 +880,15 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
     private fun fillIntentPath(resultData: Intent, resultIntent: Intent) {
         val data = resultData.data
         val path = if (data.toString().startsWith("/")) data.toString() else data!!.path
-        val uri = getFilePublicUri(File(path!!), BuildConfig.APPLICATION_ID)
-        val type = path.getMimeType()
-        resultIntent.setDataAndTypeAndNormalize(uri, type)
+
+        // copy the file to the cache directory to keep all exif data like location
+        val file = File(path!!)
+        val cacheFile = File(cacheDir, file.name)
+        file.copyTo(cacheFile, true)
+
+        val cacheUri = getFilePublicUri(cacheFile, BuildConfig.APPLICATION_ID)
+        val type = cacheFile.path.getMimeType()
+        resultIntent.setDataAndTypeAndNormalize(cacheUri, type)
         resultIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
     }

Limitations:
I don't know, if this only works on my phone or if there is a better way to do this.
I also think that this needs to be fixed when sharing a picture from this gallery app to another third-party app.

Tested with: Android 12 (MIUI 13.0.1), Fossify Gallery 1.1.3

@fabalexsie fabalexsie added feature request Issue is about a new feature in the app needs triage Issue is not yet ready for PR authors to take up labels Apr 30, 2024
@Aga-C Aga-C removed the needs triage Issue is not yet ready for PR authors to take up label Apr 30, 2024
@Aga-C
Copy link
Member

Aga-C commented Apr 30, 2024

It should be under the option, where the default is removing location data while sharing. I'd even add a setting to remove all EXIF data, as requested here for another sharing scenario (sharing from Gallery to other apps): #185.

Even better, these two requests should be done at once.

@kvibber
Copy link

kvibber commented Jul 2, 2024

I wonder if this is the reason the gallery's built-in editor is stripping out all the EXIF data from my images, including the date it was taken. In many cases, I'm editing a photo for my own use, or to upload to iNaturalist, in which case I usually want to keep all the metadata including the location, or most of the metadata but not location.

@Aga-C
Copy link
Member

Aga-C commented Jul 2, 2024

@kvibber See: #29.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issue is about a new feature in the app
Projects
None yet
Development

No branches or pull requests

3 participants