XMLHttpRequest cannot load file from Android resource folder into emulator

I am new to hybrid development. I wrote a small application that launches webview. I have XML, JS files copied to the / asset folder.

The application works fine on my Samsung tablet, but I get the following errors on the emulator

05-30 06: 09: 07.080: I / chromium (1245): [INFO: CONSOLE (0)] "XMLHttpRequest cannot load the file: ///android_asset/resource/service_config.xml. Cross-start requests are supported only for HTTP . ", source: file: ///android_asset/Startup.html (0)

I found out that this is due to the security model of Chrome browsers, and the Android browser also uses the same component as the Chrome browser. But all this is largely due to the Chrome browser, not affecting the problem on the emulator.

Appreciate any help on this issue.

Thanks,
iuq

+6
source share
1 answer

got the same error. I fixed this by changing some onCreate() action methods as follows:

 // 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"); 

Hope this helps you :)

+18
source

Source: https://habr.com/ru/post/970086/


All Articles