4

I want to display one static HTML page in my android emulator.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Rajapandian
  • 9,257
  • 24
  • 74
  • 86

3 Answers3

11

an easier way is described at Android HTML resource with references to other resources. Its working fine for me.

Put the HTML file in the "assets" folder in root, load it using:

webView.loadUrl("file:///android_asset/filename.html"); 
Community
  • 1
  • 1
Nimesh Madhavan
  • 6,290
  • 6
  • 44
  • 55
  • **Important:** The URL is not misspelled. It should be `android_asset`, not `android_assets`. – Kent Apr 19 '13 at 21:51
8

I'm assuming you want to display your own page in a webview?

Create this as your activity:

public class Test extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WebView webview = new WebView(this);
        setContentView(webview);
        try {
            InputStream fin = getAssets().open("index.html");
            byte[] buffer = new byte[fin.available()];
            fin.read(buffer);
            fin.close();
            webview.loadData(new String(buffer), "text/html", "UTF-8");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

This will read the file 'index.html' from your project assets/ folder.

Tim H
  • 13,513
  • 3
  • 17
  • 9
0

So you can simply use the WebView control to display web content to the screen, which can think of the WebView control as a browser-like view.

You can also dynamically formulate an HTML string and load it into the WebView, using the loadData() method. It takes three arguments. String htmlData, String mimeType and String encoding

First of all you create a “test.html” file and save it into assets folder.

Code:

<html>
<Body bgcolor=“yellow”>
<H1>Hello HTML</H1> 
<font color=“red”>WebView Example by Android Devloper</font>
</Body> </html>

if you want see full source code : Display HTML Content in Android

AndroidLover
  • 187
  • 1
  • 2