Hi every one, I want to get a return value from javascript in android. With Iphone, i can do it, but Android, i can't. I use loadUrl but return void not object. Anybody help me ? Thanks
+1
A:
Use addJavascriptInterface()
to add a Java object to the Javascript environment. Have your Javascript call a method on that Java object to supply its "return value".
CommonsWare
2010-07-21 12:36:51
+1
A:
Here's a hack on how you can accomplish it:
Add this Client to your WebView:
final class MyWebChromeClient extends WebChromeClient {
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
Log.d("LogTag", message);
result.confirm();
return true;
}
}
Now in your javascript call do:
webView.loadUrl("javascript:alert(functionThatReturnsSomething)");
Now in the onJsAlert call "message" will contain the returned value.
Felix Khazin
2010-07-26 20:19:22