android webview读取本地相册时“Not allowed to load local resource”
16lz
2022-07-23
不废话,按照以下操作即可
//重写shouldInterceptRequest webView.setWebViewClient(new WebViewClient() { @Override public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest webResourceRequest) { FileInputStream input; String url = ""; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { url = webResourceRequest.getUrl().toString(); } String key = "http://androidimg"; if (url.contains(key)) { String imgPath = url.replace(key, ""); try { input = new FileInputStream(new File(imgPath.trim())); WebResourceResponse response = new WebResourceResponse("image/jpg", "UTF-8", input); return response; } catch (FileNotFoundException e) { e.printStackTrace(); } } return super.shouldInterceptRequest(view, webResourceRequest); } });
//js代码let img = document.getElementById("img");function onAcceptPhoto(imgUrl) {//imgUrl = android本地图片路径let androidImgKey = "http://androidimg";img.src = androidImgKey + imgUrl;}
更多相关文章
- Pycharm安装PyQt5的详细教程
- Android--SoLoader,android动态加载so库
- Android(安卓)命令行编译、打包生成apk文件
- android手机客户端上传文件,java servlet服务器端接收并保存到服
- Android(安卓)获取存储卡路径和空间使用情况
- android Uri获取真实路径转换成File的方法
- 解决Android模拟器打不开的问题!...
- Android:计算剩余内存
- Android(安卓)打开文件管理器 获取文件的真实路径