webView中支持input的file的选择和alert弹出
alert()弹出
input的file现选择(特别说明:不同的android版本弹出的样式不同,选择文件后自动上传)
webView.setWebChromeClient(new WebChromeClient() {
//支持alert弹出
@Override
public boolean onJsAlert(WebView view, String url, String message,
JsResult result) {
return super.onJsAlert(view, url, message, result);
}
@Override
public boolean onJsConfirm(WebView view, String url,
String message, JsResult result) {
return super.onJsConfirm(view, url, message, result);
}
//webView中支持input的file现选择
// For Android 3.0+
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
if (mUploadMessage != null) return;
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
startActivityForResult( Intent.createChooser( i, "File Chooser" ), Util.FILECHOOSER_RESULTCODE );
}
// For Android < 3.0
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
openFileChooser( uploadMsg, "" );
}
// For Android > 4.1.1
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
openFileChooser(uploadMsg, acceptType);
}
- @Override
- protected void onActivityResult( int requestCode, int resultCode,
- Intent intent) {
- if (requestCode==FILECHOOSER_RESULTCODE)
- {
- if ( null == mUploadMessage) return ;
- Uri result = intent == null || resultCode != RESULT_OK ? null
- : intent.getData();
- mUploadMessage.onReceiveValue(result);
- mUploadMessage = null ;
- }
- }
最新文章
- JS 小数的常用处理方法
- 继承的小DEMO
- [课程设计]Sprint One 总结&;发表评论&;团队贡献分
- 纯css径向渐变(CSS3--Gradient)
- FZU 2218 Simple String Problem(简单字符串问题)
- log4j 分类输出
- Chrome浏览器下调试SASS
- 详解Asp.net MVC DropDownLists
- chardet安装
- &#39;Invalid update: invalid number of rows in section xx. The number of rows contained in an existing section after the update (xxx)...
- error:stray&;#39;\243&;#39;in program
- javascript中的数组对象
- Swift:一个简单的货币转换器App在iOS10中的分析和完善
- Python基础之面向对象2(封装)
- ubuntu14/16 安装python3-opencv3_百度经验
- 爬取qq号
- python 基础篇
- 从零开始一起学习SLAM | 你好,点云
- 原生js,通过document.getElementByClassName获取元素的索引值
- Python自动化开发 - 装饰器