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

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);
}

你可能感兴趣的:(Android)