解决安卓webview不支持input type=file问题
来源:互联网 发布:unity3d室内漫游下载 编辑:程序博客网 时间:2024/05/20 16:36
1.重写setWebChrameClient
mWebView.setWebChromeClient(new WebChromeClient(){ // For 3.0+ Devices (Start) protected void openFileChooser(ValueCallback uploadMsg, String acceptType) { Log.d(TAG, "openFileChooser: "); mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image"); startActivityForResult(Intent.createChooser(i, "File Browser"), FILECHOOSER_RESULTCODE); } // For Lollipop 5.0+ Devices @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public boolean onShowFileChooser(WebView mWebView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) { Log.d(TAG, "onShowFileChooser: "); if (uploadMessage != null) { uploadMessage.onReceiveValue(null); uploadMessage = null; } uploadMessage = filePathCallback; Intent intent = fileChooserParams.createIntent(); try { startActivityForResult(intent, REQUEST_SELECT_FILE); } catch (ActivityNotFoundException e) { uploadMessage = null; Toast.makeText(getBaseContext(), "Cannot Open File Chooser", Toast.LENGTH_LONG).show(); return false; } return true; } //For Android 4.1 only protected void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { mUploadMessage = uploadMsg; Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image"); startActivityForResult(Intent.createChooser(intent, "File Browser"), FILECHOOSER_RESULTCODE); } //for Android <3.0 protected void openFileChooser(ValueCallback<Uri> uploadMsg) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image"); startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE); }});重写onActivityResult在里面接收openfilechoose方法里面的图片等
@Overridepublic void onActivityResult(int requestCode, int resultCode, Intent intent){ Log.d(TAG, "onActivityResult: "); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (requestCode == REQUEST_SELECT_FILE) { if (uploadMessage == null) return; uploadMessage.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent)); uploadMessage = null; } } else if (requestCode == FILECHOOSER_RESULTCODE) { if (null == mUploadMessage) return; // Use MainActivity.RESULT_OK if you're implementing WebView inside Fragment // Use RESULT_OK only if you're implementing WebView inside an Activity Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData(); mUploadMessage.onReceiveValue(result); mUploadMessage = null; } else Toast.makeText(getBaseContext(), "Failed to Upload Image", Toast.LENGTH_LONG).show();}
阅读全文
0 0
- 解决安卓webview不支持input type=file问题
- 解决安卓webview不支持input type=file问题
- 解决WebView不支持input type=file
- 使用Android的webview将web app打包成安卓的app和解决安卓webview不支持input type=file问题
- Android WebView 不支持 H5 input type="file" 解决方法
- Android WebView 不支持 H5 input type="file" 解决方法
- Android WebView 不支持 H5 input type="file" 解决方法
- WebView实现html文件选择(input type=file),兼容安卓6.0
- android Webview支持input type=file
- android Webview支持input type=file
- input[type='file']安卓手机微信端无法调用摄像头问题
- Android-WebView-解决对选择文件<input type="file">无响应
- Android WebView不支持H5输入type =“file”解决方法
- android webview支持<input type="file"类型
- Android WebView 支持H5图片上传<input type="file">
- Android WebView支持Input type=file文件上传
- Android:让WebView支持<input type=”file”…>元素
- Android WebView H5页面 input type =“file”解决方法
- Unreal教学(1)——序言
- Unity 中使用百度语音识别发布Android程序(二)
- Android 6.0 开机流程
- Jsoup——爬虫工具的使用
- 微信小程序添加web-view业务域名,"不支持打开非业务域名"解决办法
- 解决安卓webview不支持input type=file问题
- 【第五届蓝桥杯】打印图形
- 解决Android Studio编译后安装apk报错:The APK file does not exist on disk
- python里使用正则表达式
- 【XML】xml 存档
- Android JavascriptBridge 详解(二)
- Android官方TODO-MVP项目分析(上)---View 层 Presenter 层以及 Contract 分析
- 这么多前端优化点你都记得住吗?
- java基础之集合框架--LinkedHashMap深入理解