【发布时间】:2019-08-22 04:22:14
【问题描述】:
我正在尝试使用 Android 中的 WebView 上传文件。
这是the code 正在使用中:
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean onShowFileChooser(WebView webView, final ValueCallback<Uri[]> filePathsCallback, final WebChromeClient.FileChooserParams fileChooserParams) {
Intent intent = fileChooserParams.createIntent();
LOG.d(LOG_TAG, "mime types: " + Arrays.toString(fileChooserParams.getAcceptTypes()));
// PRINTS [.jpg,.png,.tiff,.jpeg,.tif,.pdf] !!
try {
parentEngine.cordova.startActivityForResult(new CordovaPlugin() {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
// ...
}
}, intent, FILECHOOSER_RESULTCODE);
} catch (ActivityNotFoundException e) {
// ...
}
return true;
}
问题是当我必须使用的外部库 (ng-file-upload) 触发该方法的执行时,在 fileChooserParams 中作为参数传递的 mime 类型是:[.jpg,.png,.tiff,.jpeg,.tif,.pdf]。我在list of allowed mime types 中看不到其中的大部分内容。
因此,我在 LogCat 中发现了这个错误:
No activity found to handle file chooser intent.: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.GET_CONTENT cat=[android.intent.category.OPENABLE] typ=.jpg,.png,.tiff,.jpeg,.tif,.pdf }
如果我只是添加intent.setType("image/* application/pdf");,一切都会按预期工作!
现在问题是:在我想提交给cordova-android 的贡献者的Merge Request 中,我如何安全地将fileChooserParams 转换为正确的格式?
【问题讨论】:
标签: java android ionic-framework webview filepicker