The following java code helps you to show a webpage in ANDROID and enable javascript.

package com.pack;

import android.content.res.AssetManager;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.View.OnKeyListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import android.widget.Toast;

public class myHTML extends Activity {

    public void onCreate(Bundle savedInstanceState) {

        WebView webview = (WebView)findViewById(;
        TextView tv = (TextView)findViewById(;

        tv.setOnKeyListener(new OnKeyListener() {
 public boolean onKey(View v, int keyCode, KeyEvent event) {

 return false;


        //  setContentView(webview);

              final Activity activity = this;
              webview.setWebChromeClient(new WebChromeClient() {
           public void onProgressChanged(WebView view, int progress) {
             activity.setProgress(progress * 10000);
             Toast.makeText(activity, "Loading " , Toast.LENGTH_SHORT).show();

              webview.setWebViewClient(new WebViewClient() {
              public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
              Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();

         String summary = "HELLO";

         /*To load from a string use loadDataWithBaseURL  */
         webview.loadDataWithBaseURL("",summary, "text/html", "utf-8", "");

         /* To load from a file use loadUrl(remote or local) */

        }catch(Exception e){
         Toast.makeText(myHTML.this,e.getMessage(), Toast.LENGTH_SHORT).show();



  1. ramesh September 26, 2011 at 11:11 am

    what is main different between webchromclient and webclient in android?

  2. raaj November 26, 2012 at 11:05 am

    Hi actually i m new for android app dev. can you please tell me how to create android elements using javascript without using webview ?

  3. pavan April 22, 2013 at 1:31 pm

    Thank you very much, helped your application to me.


Leave a Reply

Your email address will not be published. Required fields are marked *




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.