Loading local .HTML-file with WebView
12,376
Change file:///assets/hello.html
to file:///android_asset/hello.html
. This assumes that your HTML file is located at assets/hello.html
in your project.
Also, move your <h1>
element into the <body>
, so that it will actually work.
Author by
David
Updated on June 28, 2022Comments
-
David almost 2 years
I've read many descriptions on how to make this work, but it doesn't in my emulator, which is really frustrating. Should be piece of cake!
I made a supersimple html-file:
<html> <head> <h1> Hello </h1> </head> <body> </body> </html>
And then I use this java code to implement it:
package com.path.path; import android.app.Activity; import android.os.Bundle; import android.webkit.WebView; public class hello extends Activity { WebView webView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.hello); String url = "file:///assets/hello.html"; webView = (WebView) this.findViewById(R.id.char_view); webView.loadUrl(url); }
}
When I load this page in the emulator it says the page is not available. What am I missing??
Thanks!
-
David over 10 yearsIt was as easy as that, been stuck with this silly issue all day! Thank you CommonsWare, I would vote up your Answer if I had those 15 rep..
-
Ryan Langton over 10 yearsDavid you don't have to up vote, this should be selected as the answer