通过 Intent 共享照片时删除 EXIF 位置数据

时间:2023-03-21
本文介绍了通过 Intent 共享照片时删除 EXIF 位置数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我最近将我的应用程序切换到了 Scoped Storage.但是,我注意到,当我从应用程序内(通过 Intent)共享图像时,GPS 位置数据会从图像的 Exif 元数据中删除.我知道 Scoped Storage 对访问图像的 Exif 位置数据有一些限制,并且我知道权限 <uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION"/>,但是添加此权限似乎在共享图像时没有任何效果.知道如何通过 Intent 共享图像,同时将位置数据保留在图像的 Exif 数据中吗?

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?

这是我的代码:

 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!

推荐答案

我在 Android 11 上的体验.

My experiences on Android 11.

也必须在运行时请求 ACCESS_MEDIA_LOCATION.

Have to request ACCESS_MEDIA_LOCATION at runtime too.

服务应用应具有所有文件访问权限",以便接收应用从 exif 读取纬度、经度.

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

如果服务应用程序可以访问所有文件,则不需要 MediaStore.setRequireOriginal 从文件中读取 lat,lon 本身.

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

(我从未使用过 MediaStore.setRequireOriginal,但现在将进行调查).

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

这篇关于通过 Intent 共享照片时删除 EXIF 位置数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:使用 Wifi 时查找当前位置有效,但使用 GPS 时失败 下一篇:Android 上服务的良好做法

相关文章