問題描述
我最近將我的應用程序切換到了 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 位置數據的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!