简体   繁体   中英

How to get mime file type in android

I want to know how to get mime file type

@Override
 public boolean shouldOverrideUrlLoading(WebView webview, String url)
{
    boolean error = false; 
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String mimeType = fileNameMap.getContentTypeFor(url);


if(mimeType.equals("text/html") || mimeType.equals("application/xhtml+xml"))
{
    webview.loadUrl(url);
    return true;

}
}

but its not working , Please any body help me on this

public static String getMimeType(String url)
{
    String type = null;
    String extension = MimeTypeMap.getFileExtensionFromUrl(url);
    if (extension != null) {
        MimeTypeMap mime = MimeTypeMap.getSingleton();
        type = mime.getMimeTypeFromExtension(extension);
    }
    return type;
}

The url can be a file path or a Stable Web URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM