怎么解决安卓4.4.1和4.4.2 webview 不支持<input type="file" />
2015-07-19
展开全部
mWebView.getSettings().setJavaScriptEnabled(true);
这个只是支持javascript,对html5不起作用
可以阅读下WebChromeClient的源码,我就摘抄下吧
/**
* Tell the client to open a file chooser.
* @param uploadFile A ValueCallback to set the URI of the file to upload.
* onReceiveValue must be called to wake up the thread.a
* @param acceptType The value of the 'accept' attribute of the input tag
* associated with this file picker.
* @hide
*/如果不管用添加这个方法
public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType,String capture)
因为Android API变化了。
这个只是支持javascript,对html5不起作用
可以阅读下WebChromeClient的源码,我就摘抄下吧
/**
* Tell the client to open a file chooser.
* @param uploadFile A ValueCallback to set the URI of the file to upload.
* onReceiveValue must be called to wake up the thread.a
* @param acceptType The value of the 'accept' attribute of the input tag
* associated with this file picker.
* @hide
*/如果不管用添加这个方法
public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType,String capture)
因为Android API变化了。
推荐于2016-01-26 · 知道合伙人软件行家
关注
展开全部
android里webview不支持input type=file的解决方法
1.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);
}
}
1.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);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询