Skip to content Skip to sidebar Skip to footer

Local Html Does Not Open On Android

I have a Android Studio project, this project should have local HTML files. I don't know if I understand the files structure, or the problem is another. The file is not opened. Onl

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;

@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mWebView = (WebView) findViewById(R.id.activity_main_webview);
    // Enable JavascriptWebSettingswebSettings= mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    mWebView.loadUrl("file:///android_asset/index.html");

}

Post a Comment for "Local Html Does Not Open On Android"