Hi, Dan

The Javascript is already in memory (i.e. loaded by Webkit): I can
call functions/methods on that code from Java.

mWebView.loadUrl("file///android_assets/index.html"); // loads a bunch
of javascript.

The onPageFinished method runs, and the page is ready.

This javascript doesn't do anything except initialize itself and wire
up a few listeners/onclick type things.

I can verify that, by invoking a method on an JS object created in
global:

mWebView.loadUrl("javascript:mLoadedEarlier.method();");

It is not doing anything exotic e.g. setInterval() or tight looping.

Once I've done that, I'd like to add my newly minted javascript
interface - the Java object myAvailableOnlyLaterObject:

mWebView.addJavascriptInterface(myAvailableOnlyLaterObject,
"MyLateJavaObject");

Methods will be called on MyLateJavaObject in a click handler, i.e.
some time later. When the appointed time comes for the user to click,
triggering the call, the ReferenceError is reported.

Should I be able to do what I'm asking, and I'm doing it wrong? or am
I holding it wrong?

James

On Jan 20, 7:20 pm, Dan <[email protected]> wrote:
> James,
>
> Have you verified your JavaScript isn't already executed before this
> event occurs?
>
> -Dan
>
> On Jan 20, 9:43 am, jamesh <[email protected]> wrote:
>
> > Hi,
>
> > I'm trying to add Java objects to a WebView, such that they are
> > available to Javascript.
>
> > I can prove that if I do:
>
> > mWebView.addJavascriptInterface(myAvailableAtLoadTimeObject,
> > "MyJavaObject");
> > mWebView.load("file:///android_assets/index.html");
>
> > I can call methods from Javascript:
>
> > MyJavaObject.callableFunction(); // callableFunction is a Java method
> > on myAvailableAtLoadTimeObject.
>
> > or from Java:
> > mWebView.loadUrl("javascript:MyJavaObject.callableFunction();");
>
> > However, if WebViewClient.onPageFinished() has occurred, and then I
> > try:
>
> > mWebView.addJavascriptInterface(myAvailableOnlyLaterObject,
> > "MyLateJavaObject");
> > mWebView.loadUrl("javascript:MyLateJavaObject.callableFunction();");
>
> > I get an error reported from Javascript:
> > Uncaught ReferenceError: MyLateJavaObject is not defined
>
> > What am I missing, or doing wrong?
>
> > Thanks,
>
> > James

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" 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-developers?hl=en

Reply via email to