Android Android - 10 days ago 5
Android Question

need help for android webview

I am using this simple code http://www.w3schools.com/js/tryit.asp?filename=tryjs_alert

This shows me alert box, but when I try it with webview in android, it doen't show me an alert box

webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("file:///android_asset/test.html");


What am I doing wrong or what is missing here

Thanks


Answer

I finally got the solution for the question asked above by me :

package android.com.Webview;

import android.app.Activity;

import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class WebviewActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        WebView webview = (WebView) findViewById(R.id.webview);
        webview.getSettings().setJavaScriptEnabled(true);

        WebSettings webSettings = webview.getSettings();

        webSettings.setJavaScriptEnabled(true);

        webSettings.setBuiltInZoomControls(true);

        webview.requestFocusFromTouch();

        webview.setWebViewClient(new WebViewClient());
        webview.setWebChromeClient(new WebChromeClient());

         webview.loadUrl("file:///android_asset/test.html");
    }
}

Comments