EXIF location data removed when sharing photo via Intent
Asked Answered
H

1

7

I have recently switched my app to Scoped Storage. However, I have noticed that when I share an image from within the app (via an Intent), the GPS location data is removed from the image's Exif metadata. I am aware that Scoped Storage has some restrictions on accessing the Exif location data of an image and I am aware about the permission <uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />, however adding this permission does not seem to have any effect when sharing the image. Any idea how to share images via Intent while retaining the location data in the image's Exif data?

Here is my code:

 val imageUri = mediaList[photo_view_pager.currentItem].uri

 val intent = Intent().apply {
     val mediaType = MimeTypeMap.getSingleton()
        .getMimeTypeFromExtension("jpg")
     putExtra(Intent.EXTRA_STREAM, imageUri)
     type = mediaType
     action = Intent.ACTION_SEND
     flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
 }

 startActivity(Intent.createChooser(intent, getString(R.string.share_hint)))

Thanks a lot in advance for any help!

Herren answered 19/7, 2021 at 14:23 Comment(6)
Is it because you thanked in advance that nobody reacted? You better remove it. Your problem is quite interesting though.Costin
If your app opens the file itself, can it read lat and lon?Costin
Yes, my app can read the file's location using the ACCESS_MEDIA_LOCATION permission, MediaStore.setRequireOriginal(photoUri)and a content resolver, however the location is still not included in the photo when shared. I have also tried to amend the initial Uri used for sharing to photoUri = MediaStore.setRequireOriginal(photoUri), however this will cause the photo not to be loaded into the third-party messaging app or causes a crash.Herren
photoUri = MediaStore.setRequireOriginal(photoUri) You did that in the serving app? Did you also try in receiving app?Costin
I presume the serving app is my app and the receiving app is the Gmail app, WhatsApp or any other messaging app. Please correct me in case I got this wrong. I tried it in the serving app (my app). It seems like the the receiving app does not recognise the amended Uri. I tried it with a few apps: Gmail does not load the image correctly, while ProtonMail does not load the image at all. Signal Messenger crashes.Herren
try <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />Damiandamiani
C
1

My experiences on Android 11.

Have to request ACCESS_MEDIA_LOCATION at runtime too.

The serving app should have 'all files access' in order for the receiving app to read lat, lon from exif.

If the serving app has all files access it does not need the MediaStore.setRequireOriginal to read lat,lon itself from file.

(I never used MediaStore.setRequireOriginal but will investigate now).

Costin answered 20/7, 2021 at 10:22 Comment(2)
Thanks! I will continue investigating too. Just for your information, my app does not have "all files access". It is a camera app and I am unsure if I could justify using it (the app is on Google Play and I would need to submit a special request for using "all files access"). It might be worth mentioning that the app is only accessing the photos it created.Herren
I have tried every possible combination of permissions (all files access, ACCESS_MEDIA_LOCATION,...) but no luck yet (on Android 10). I have noticed that while sharing the photo via Gmail removes the location Exif data, sharing it via Google Drive retains it (even with no ACCESS_MEDIA_LOCATION and all files access permission). Hence, it seems like the receiving app does also affect it, but would wonder if there is a way to influence this from the serving app (maybe with a flag in the Intent)...Herren

© 2022 - 2024 — McMap. All rights reserved.