怎么解决安卓5.1.1 webview 不支持<input type="file" />
android里webview不支持input type=file的解决方法
activity定义
public ValueCallback<Uri> mUploadMessage;
public final static int FILECHOOSER_RESULTCODE = 1;
2.扩展WebChromeClient
WebChromeClient chromeClient = new WebChromeClientImpl();
view.setWebChromeClient(chromeClient);
3.实现WebChromeClientImpl类
private class WebChromeClientImpl extends WebChromeClient{
//扩展支持alert事件
@Override
public boolean onJsAlert(WebView view, String url, String message,JsResult result) {
Builder builder = new Builder(view.getContext());
builder.setTitle("商机通提示").setMessage(message).setPositiveButton("确定", null);
builder.setCancelable(false);
builder.setIcon(R.drawable.ic_launcher);
AlertDialog dialog = builder.create();
dialog.show();
result.confirm();
return true;
}
//扩展浏览器上传文件
//3.0++版本
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
activity.startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);
}
//3.0--版本
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
activity.startActivityForResult(Intent.createChooser(i, "file Browser"),FILECHOOSER_RESULTCODE);
}
}