XMLHttpRequest无法在模拟器上从android资源文件夹加载文件

iuq*_*iuq 6 android android-emulator hybrid-mobile-app

我是混合动力开发的新手.我写了一个小应用程序启动webview.我有XML,JS文件复制在/ asset文件夹中.

应用程序在我的三星平板电脑上工作正常,但我在模拟器上得到以下错误

05-30 06:09:07.080:I/chromium(1245):[INFO:CONSOLE(0)]"XMLHttpRequest无法加载file:///android_asset/resource/service_config.xml.只有HTTP支持交叉原始请求. ",source:file:///android_asset/Startup.html(0)

我知道它发生的原因是Chrome浏览器安全模型和android webview也使用与chrome浏览器相同的组件.但所有这些主要与Chrome浏览器没有解决模拟器上的问题有关.

感谢您对此问题的任何帮助.

谢谢,
iuq

Ric*_*d R 18

得到了同样的错误.我通过在活动onCreate()方法中更改webview的一些设置来修复它,如下所示:

// settings for webview
mWebView = (WebView)findViewById(R.id.activity_main_webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginState(PluginState.ON);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setAllowContentAccess(true);
mWebView.getSettings().setAllowFileAccessFromFileURLs(true);
mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);

//load file
mWebView.loadUrl("file:///android_asset/www/index.html");
Run Code Online (Sandbox Code Playgroud)

希望可能对你有所帮助:)