In Android 9, even if you specify MIME_TYPE of MediaStore as "video/mp4" and DISPLAY_NAME as "fileName.mp4", it will be saved as a 3gp file.
In Android 10, it works without problems.
How to solve this problem
val contentValues = ContentValues().apply {
put(MediaStore.Video.Media.TITLE, fileName)
put(MediaStore.Video.Media.DISPLAY_NAME, fileName)
put(MediaStore.Video.Media.DATE_ADDED, dateSeconds)
put(MediaStore.Video.Media.DATE_MODIFIED, dateSeconds)
put(MediaStore.Video.Media.MIME_TYPE, "video/mp4")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
put(MediaStore.Video.Media.IS_PENDING, 1)
}
}
val itemUri = contentResolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, contentValues)
contentResolver.openOutputStream(itemUri, "w")?.use { os ->
tempFile.inputStream().copyTo(os)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
contentValues.clear()
contentValues.apply {
put(MediaStore.Video.Media.IS_PENDING, 0)
}
contentResolver.update(itemUri, contentValues, null, null)
}