Java: MimeTypeMap fail to return extension for a filename contains spaces


Sample error code:

import android.webkit.MimeTypeMap;
...
String extension = MimeTypeMap.getFileExtensionFromUrl(url);

Solution:
Replace blank space to %20

String extension = MimeTypeMap.getFileExtensionFromUrl(url.replace(" ","%20"));

Leave a Reply