Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alert is not appear from web view in android?

I use the sample provided by Google for demonstrating two way communication between JavaScript and Java ,

ref[1]:

http://code.google.com/p/apps-for-android/source/browse/trunk/Samples/WebViewDemo/src/com/google/android/webviewdemo/WebViewDemo.java

The functionality is working fine. I am able to call JavaScript function from Java and callback the Java function from JavaScript.

The problem is when I use an alert inside a JavaScript function it won`t appear, but the functionality inside the function is working properly.

Why does alert("test") inside a JavaScript function not appear in Android. I load the JavaScript in a web-view. When I a clicking button in Android I call the function, but it does not appear.

If anyone knows the problem, pealse help me out.

Thanks

like image 499
Karthi Avatar asked Jun 24 '11 03:06

Karthi


1 Answers

setContentView(R.layout.main);
        WebView webview = (WebView) findViewById(R.id.webview);

        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");

this code working perfect and shows me alert box.. and this is my
test.html

<html>
<head>
<script type="text/javascript">
function show_alert()
{
alert("Hello! I am an alert box!");
}
</script>
</head>
<body>

<input type="button" onclick="show_alert()" value="Show alert box" />

</body>
</html>
like image 77
Android Avatar answered Oct 25 '22 12:10

Android