'Need help to implement WebViewAssetLoader
I have converted an existing game written in HTML, CSS, and JavaScript into an Android app by wrapping the game in a native Java app using WebView (tutorial). The game uses HTML5 Canvas for rendering. All files are stored locally.
The game contains several JS files, which is causing CORS / same-origin errors on a physical device, while running without errors on a virtual device. Apparently the solution is to implement WebViewAssetLoader.
Unfortunately the documentation does not provide a lot of context, and for the inexperienced android developer it is unclear how to actually implement this functionality. Any help or advice is much appreciated.
Solution 1:[1]
Just copy paste your source code in assets folder and then use this code to load the index.html file in your webview.
wv.setWebViewClient(new WebViewClient());
wv.getSettings().setLoadWithOverviewMode(true);
wv.getSettings().setUseWideViewPort(true);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setPluginState(WebSettings.PluginState.ON);
wv.getSettings().setAllowFileAccess(true);
wv.getSettings().setAllowContentAccess(true);
wv.getSettings().setAllowFileAccessFromFileURLs(true);
wv.getSettings().setAllowUniversalAccessFromFileURLs(true);
wv.loadUrl("file:///android_asset/index.html");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Arab Ware |
