Hi,
I have been able to bind a Java object to JavaScript. I am also able
to call JavaScript functions from Java
1. Java functions calling JavaScript
override the onLoadResource method and use the addJavaScriptInterface
method
eg:
wv.setWebViewClient(new WebViewClient() {
public void onLoadResource(WebView w, String url)
{
//JavaAdder Adder = new JavaAdder();
SomeClass aj = new SomeClass();
w.addJavascriptInterface(aj, "EARL");
}
});
and SomeClass is
public class SomeClass
{
public void someMethod() { ... }
}
Then, to call this method from javascript, use
window.EARL.someMethod(...);
The java object methods are added to the DOM
2. To call a JavaScript function from Java use
wv.loadUrl("javascript:someFunction();");
Hope this helps,
Cheers,
Earlence
On Jan 4, 6:47 pm, Mike Hearn <[email protected]> wrote:
> You have to enable it using getSettings().setJavaScriptEnabled() but
> after that all the same stuff you get in the regular browser. There is
> also a method that lets you bind a Java object into JavaScript but
> it's woefully under documented, and I haven't tried it myself yet
> (planning on doing so soon).
>
> On Jan 1, 2:19 pm, Tez <[email protected]> wrote:
>
>
>
> > Hi,
>
> > I'm trying to launch a Web2.0 app from within a WebView. Can anyone
> > tell me what kind of JavaScript functionality is available to a web
> > app within the WebView environment.
>
> > Cheers,
> > Earlence- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Android Discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---