MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType) could return null.
Try to get fileExtension by splitting mimeType:
<code>
String[] split = mimeType.split("/");
String guessedExt = split.length > 1 ? split[1] : split[0];
</code>
(see: getMediaFileName method)