Android webview会自动检测网页中的文件吗?

时间:2017-07-07 06:16:18

标签: java android html

public static String getMimeType(Context context, Uri uri) {
    String extension; //Check uri format to avoid null 
    if (uri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
        //If scheme is a content 
        final MimeTypeMap mime = MimeTypeMap.getSingleton();
        extension = mime.getExtensionFromMimeType(context.getContentResolver().getType(uri));

    } else {
        //If scheme is a File 
        //This will replace white spaces with %20 and also other special characters. This will avoid returning null values on file name with spaces and special characters. 
        extension = MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(new File(uri.getPath())).toString());

    }
    return extension;

}

我试过这不起作用

0 个答案:

没有答案