Display a local HTML file using Android Webview   #


import android.app.Activity; import android.os.Bundle; import android.view.Window; import android.webkit.WebView; import com.codercrunch.app.R; //Let’s say the html file is called as index.html and is located in the asset folder of the app. //The following Activity shows how to load it and display the html in the webview. public class AboutActivity extends Activity { String summary = ""; @Override public void onCreate(Bundle savedInstanceState) { this.requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); setContentView(R.layout.about_activity); // webview WebView webview = new WebView(this); setContentView(webview); try { // get inputstream InputStream fin = getAssets().open("index.html"); byte[] buffer = new byte[fin.available()]; fin.read(buffer); fin.close(); // load it webview.loadData(new String(buffer), "text/html", "UTF-8"); } catch (IOException e) { e.printStackTrace(); } } }

Loading Please Wait...