将fileChooserParams中的mime类型转换为Intent.setType的正确格式

将fileChooserParams中的mime类型转换为Intent.setType的正确格式,第1张

将fileChooserParams中的mime类型转换为Intent.setType的正确格式

我使用以下代码改进了解决方案

   // Validation utility for mime types    private List<String> extractValidMimeTypes(String[] mimeTypes) {        List<String> results = new ArrayList<String>();        List<String> mimes;        if (mimeTypes.length() == 1 && mimeTypes[0].contains(",")) { mimes = Arrays.asList(mimeTypes[0].split(","));        } else { mimes = Arrays.asList(mimeTypes);        }        MimeTypeMap mtm = MimeTypeMap.getSingleton();        for (String mime : mimes) { if (mime != null && mime.trim().startsWith(".")) {     String extensionWithoutDot = mime.trim().substring(1, mime.trim().length());     String derivedMime = mtm.getMimeTypeFromExtension(extensionWithoutDot);     if (derivedMime != null && !results.contains(derivedMime)) {         // adds valid mime type derived from the file extension         results.add(derivedMime);     } } else if (mtm.getExtensionFromMimeType(mime) != null && !results.contains(mime)) {     // adds valid mime type checked agains file extensions mappings     results.add(mime); }        }        return results;    }public boolean onShowFileChooser(WebView webView, final ValueCallback<Uri[]> filePathsCallback, final WebChromeClient.FileChooserParams fileChooserParams) {    Intent intent = fileChooserParams.createIntent();    List<String> validMimeTypes = extractValidMimeTypes(fileChooserParams.getAcceptTypes());    if (validMimeTypes.isEmpty()) {        intent.setType(DEFAULT_MIME_TYPE);    } else {        intent.setType(String.join(" ", validMimeTypes));    }    ...

有关更多详细信息,请参见我的请求请求。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5490406.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存