Local HTML Does Not Open On Android
Solution 1:
The path is wrong.
It's not
file:///assets/...
but:
file:///android_asset/...
Solution 2:
to fix this create a folder in "main" called "android_asset" and also create another folder called "assets" and place your html file in assets and call using this mWebView.loadUrl("file:///android_asset/YOUR HTML FILE.html");
I had the same problem and even though I dont call mWebView.loadUrl("file:///assets/YOUR HTML FILE.html"); it still some how works. which i find strange because thats where the html actually is!
You may have to duplicate your htmls for older android versions and place in android_asset also.
So again your folders should look like this main/android_assets/assets/YOUR HTML.html and main/assets/ and call with mWebView.loadUrl("file:///android_asset/YOUR HTML FILE.html");
Heres how my oncreate looks.
private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
// Enable Javascript
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("file:///android_asset/index.html");
}
Post a Comment for "Local HTML Does Not Open On Android"