我正在尝试使用 Android 中的 WebView 上传文件。
This is the code in use:
@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;
}
The problem是当我使用外部库时must use (ng-file-upload
) 触发此方法的执行,在 fileChooserParams 中作为参数传递的 mime 类型为:[.jpg,.png,.tiff,.jpeg,.tif,.pdf]
。我在其中没有看到其中的大部分内容允许的 mime 类型列表.
结果我在 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");
一切都按预期进行!
Now the question在里面合并请求我想提交给科尔多瓦安卓的贡献者我如何安全地转换文件选择器参数到正确的格式?