Fix issue on Android 21

This commit is contained in:
Benoit Marty 2021-07-15 17:30:48 +02:00
parent bfc70be5bb
commit 343ea42ef5
3 changed files with 11 additions and 2 deletions

View File

@ -31,6 +31,8 @@ object MimeTypes {
const val Jpeg = "image/jpeg" const val Jpeg = "image/jpeg"
const val Gif = "image/gif" const val Gif = "image/gif"
const val Ogg = "audio/ogg"
fun String?.normalizeMimeType() = if (this == BadJpg) Jpeg else this fun String?.normalizeMimeType() = if (this == BadJpg) Jpeg else this
fun String?.isMimeTypeImage() = this?.startsWith("image/").orFalse() fun String?.isMimeTypeImage() = this?.startsWith("image/").orFalse()

View File

@ -141,7 +141,7 @@ fun Uri.toMultiPickerAudioType(context: Context): MultiPickerAudioType? {
MultiPickerAudioType( MultiPickerAudioType(
name, name,
size, size,
context.contentResolver.getType(this), sanitize(context.contentResolver.getType(this)),
this, this,
duration duration
) )
@ -150,3 +150,11 @@ fun Uri.toMultiPickerAudioType(context: Context): MultiPickerAudioType? {
} }
} }
} }
private fun sanitize(type: String?): String? {
if (type == "application/ogg") {
// Not supported on old system
return "audio/ogg"
}
return type
}

View File

@ -74,7 +74,6 @@ class VoiceMessageHelper @Inject constructor(
voiceRecorder.getVoiceMessageFile() voiceRecorder.getVoiceMessageFile()
} }
try { try {
// TODO Improve this
voiceMessageFile?.let { voiceMessageFile?.let {
val outputFileUri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileProvider", it) val outputFileUri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileProvider", it)
return outputFileUri return outputFileUri