方法如下:
在自定义的WebChromeClient中实现如下方法(主要是为了保证不同android版本上的兼容性):
```java
public void openFileChooser(final ValueCallback uploadMsg)
public void openFileChooser(ValueCallback uploadMsg, String acceptType)
public void openFileChooser(ValueCallback uploadMsg, String acceptType, String capture)
```
并配置proguard保证其不被混淆掉。
在openFileChooser中使用如下Intent调用系统文件浏览器:
```java
private Intent createDefaultOpenableIntent(final Context ctx) {
// Create and return a chooser with the default OPENABLE
// actions including the camera, camcorder and sound
// recorder where available.
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
Intent chooser = createChooserIntent(ctx, createCameraIntent(), createCamcorderIntent(),
createSoundRecorderIntent());
chooser.putExtra(Intent.EXTRA_INTENT, i);
return chooser;
}
```
然后:
```java
startActivityForResult()
```
在主Activity的onActivityResult()中
调用ValueCallback对象的onReceiveValue()方法中将选择文件的Uri传回。
但是问题还是来了,这样做了之后在4.4系统上WebView不会回调openFileChooser方法导致没法显示出选择文件的Activity。
另外对于选择文件的应用也不能假定所有的Android系统上都有。
所以终极解决方案就是拥有自主可控的WebView。