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 ;
- }
- }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。