Use file extension based on MIME type
It uses the most common extension for the given MIME type. Test: Manual Change-Id: I3d4aea85fcd42088ed19898054db7225954d3401 Signed-off-by: Taesu Lee <taesu82.lee@samsung.com>
This commit is contained in:
@@ -333,20 +333,26 @@ public class MmsUtils {
|
||||
String srcName;
|
||||
if (part.isAttachment()) {
|
||||
String contentType = part.getContentType();
|
||||
final String extension = ContentType.getExtensionFromMimeType(contentType);
|
||||
if (ContentType.isImageType(contentType)) {
|
||||
// There's a good chance that if we selected the image from our media picker the
|
||||
// content type is image/*. Fix the content type here for gifs so that we only
|
||||
// need to open the input stream once. All other gif vs static image checks will
|
||||
// only have to do a string comparison which is much cheaper.
|
||||
final boolean isGif = ImageUtils.isGif(contentType, part.getContentUri());
|
||||
contentType = isGif ? ContentType.IMAGE_GIF : contentType;
|
||||
srcName = String.format(isGif ? "image%06d.gif" : "image%06d.jpg", index);
|
||||
if (extension != null) {
|
||||
srcName = String.format("image%06d.%s", index, extension);
|
||||
} else {
|
||||
// There's a good chance that if we selected the image from our media picker
|
||||
// the content type is image/*. Fix the content type here for gifs so that
|
||||
// we only need to open the input stream once. All other gif vs static image
|
||||
// checks will only have to do a string comparison which is much cheaper.
|
||||
final boolean isGif = ImageUtils.isGif(contentType, part.getContentUri());
|
||||
contentType = isGif ? ContentType.IMAGE_GIF : contentType;
|
||||
srcName = String.format(isGif ? "image%06d.gif" : "image%06d.jpg", index);
|
||||
}
|
||||
smilBody.append(String.format(sSmilImagePart, srcName));
|
||||
totalLength += addPicturePart(context, pb, index, part,
|
||||
widthLimit, heightLimit, bytesPerImage, srcName, contentType);
|
||||
hasVisualAttachment = true;
|
||||
} else if (ContentType.isVideoType(contentType)) {
|
||||
srcName = String.format("video%06d.mp4", index);
|
||||
srcName = String.format("video%06d.%s", index,
|
||||
extension != null ? extension : "mp4");
|
||||
final int length = addVideoPart(context, pb, part, srcName);
|
||||
totalLength += length;
|
||||
smilBody.append(String.format(sSmilVideoPart, srcName,
|
||||
@@ -358,7 +364,8 @@ public class MmsUtils {
|
||||
smilBody.append(String.format(sSmilPart, srcName));
|
||||
hasNonVisualAttachment = true;
|
||||
} else if (ContentType.isAudioType(contentType)) {
|
||||
srcName = String.format("recording%06d.amr", index);
|
||||
srcName = String.format("recording%06d.%s",
|
||||
index, extension != null ? extension : "amr");
|
||||
totalLength += addOtherPart(context, pb, part, srcName);
|
||||
final int duration = getMediaDurationMs(context, part, -1);
|
||||
Assert.isTrue(duration != -1);
|
||||
|
||||
Reference in New Issue
Block a user