Fix crash when saving media with octet stream content type.

This commit is contained in:
Cody Henthorne 2021-07-08 15:38:24 -04:00
parent 1f28a30ace
commit 5ec9c1cd90
2 changed files with 9 additions and 0 deletions

View file

@ -314,6 +314,10 @@ public class MediaUtil {
return isImageType(contentType) || isVideoType(contentType);
}
public static boolean isImageVideoOrAudioType(String contentType) {
return isImageOrVideoType(contentType) || isAudioType(contentType);
}
public static boolean isImageAndNotGif(@NonNull String contentType) {
return isImageType(contentType) && !isGif(contentType);
}

View file

@ -184,6 +184,11 @@ public class SaveAttachmentTask extends ProgressDialogAsyncTask<SaveAttachmentTa
String extension = fileParts[1];
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
if (MediaUtil.isOctetStream(mimeType) && MediaUtil.isImageVideoOrAudioType(contentType)) {
Log.d(TAG, "MimeTypeMap returned octet stream for media, changing to provided content type [" + contentType + "] instead.");
mimeType = contentType;
}
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, fileName);
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, mimeType);