WebView android sdk 25加载“file:///..."失败解决

来源:互联网 发布:cats vs dogs数据下载 编辑:程序博客网 时间:2024/06/01 08:16
String url = "file:///android_asset/chars/charts.html";if (webView != null) {    webView.loadUrl(url);} 

报错:
I/chromium: [INFO:CONSOLE(40)] “XMLHttpRequest cannot load file:///android_asset/FusionCharts/qeypdata.xml. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.”, source: file:///android_asset/chars/charts.js (40)

解决办法:

webView.getSettings().setJavaScriptEnabled(true);webView.getSettings().setDomStorageEnabled(true);webView.getSettings().setSupportZoom(false);        webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);webView.getSettings().setAllowFileAccess(true);webView.getSettings().setAllowContentAccess(true);if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){                       webView.getSettings().setAllowFileAccessFromFileURLs(true);                 webView.getSettings().setAllowUniversalAccessFromFileURLs(true);}
阅读全文
0 0
原创粉丝点击