[英]MediaStore contentResolver.insert() creates copies instead of replacing the existing file when taking photos (Android Q: 29)
[英]Android ContentResolver creates file with random filename
我正在嘗試使用此代碼使用 ContentResolver 創建一個 GIF
val fileName = "mygif.gif"
// Add a specific media item.
val resolver = applicationContext.contentResolver
// Find all video files on the primary external storage device.
val videoCollection =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY)
} else {
MediaStore.Images.Media.EXTERNAL_CONTENT_URI
}
val gifDetails = ContentValues().apply {
put(MediaStore.Images.Media.DISPLAY_NAME, fileName)
}
resolver.insert(videoCollection, gifDetails)?.let { uri ->
val os = resolver.openOutputStream(uri)
// [...] creates GIF with Outputstream
}
我的文件已正確創建,但 Android 將其命名為16118154646.jpg
而不是mygif.gif
。 名稱和擴展名均未正確設置。 這個怎么做?
此代碼不適用於 Android <= 28,但適用於 Android >= 29。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.