XMLHttpRequest cannot load file from android asset folder on emulator

后端 未结 1 1831
一整个雨季
一整个雨季 2021-01-02 22:57

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

App works fine on my samsung tablet

相关标签:
1条回答
  • 2021-01-02 23:20

    got the same error. I fixed it by changing some settings of the webview in the activities onCreate() method 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 that might help you :)

    0 讨论(0)
提交回复
热议问题