To show a static html page in android

I am trying to show an html file in my assets folder but in web view i am seeing white blank page. I got similar example from stackflow only.

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final String mimeType="text/html";
    final String encoding="UTF-8";
    String htmlString="<html><body>";
    Document doc;
    WebView wv= new WebView(this);
    Elements link = null;


    setContentView(wv);
    try{
        InputStream in=getAssets().open("myweb.html");
        byte[] buffer= new byte[in.available()];
        in.read(buffer);
        in.close();
        wv.loadData(new String(buffer), mimeType, encoding);
    }
    catch(IOException e)
    {
        Log.d("MyWebView", e.toString());
    }
}

  • How to attach android source in IntelliJ 10?
  • Android: How handle message error from the server using Volley?
  • Android link to wireless & Network Settings
  • Smart App Banners; Windows Store app HTML meta tag equivalent for Android/Google Play?
  • CoordinatorLayout with RecyclerView & CollapsingToolbarLayout
  • Image View not Wrapping Contents
  • Related posts:

    How to use data-binding with Fragment
    Saving data upon closing app and retrieving that data
    Unknown exception in parseSdkContent
    Benefits of switching from Eclipse to IntelliJ IDEA for Android development
    OpenStreetMap in Android
    EditText setError is out of place in BottomSheetDialog
  • PhoneGap Build won't build for Android with PushPlugin
  • Android - Include native StageFright features in my own project
  • How to use Universal image loader for video thumbnails listing in android?
  • Logcat standalone client
  • How to implement a MediaPlayer restart on errors in Android?
  • Android TextView SingleLine field hides long text
  • 4 Solutions collect form web for “To show a static html page in android”

    you can load the content of the web view using

    // add a webview with id @+id/the_webwiev to your main.xml layout file
    WebView wv = (WebView)findViewById(R.id.the_webview);
    wv.loadUrl("file:///android_asset/myweb.html");
    

    Uhm, did you try following the WebView example from the official webpage? It’s really simple.

    http://developer.android.com/resources/tutorials/views/hello-webview.html

    I followed that and had no trouble implementing a WebView. Your code looks overly complicated for something that is quite simple.

    If your file is called pmi_help.html (and located in the /assets/ folder), you load it using:

        mWebView.loadUrl("file:///android_asset/pmi_help.html");
    

    Put your html page in asset > www, then load:

    mWebView.loadUrl("file:///android_asset/index1.html");
    

    Anyway, don’t forget this:
    Before this will work, however, your application must have access to the Internet. To get Internet access, request the INTERNET permission in your manifest file. For example:

    <manifest ... >
        <uses-permission android:name="android.permission.INTERNET" />
        ...
    </manifest>
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.