You should call window.test.incr(100) instead.
-- Have you read my blog ? http://dtmilano.blogspot.com On Mar 17, 4:28 am, sherwin huang <sherwin....@gmail.com> wrote: > hi > I'm trying to call a java method from javascript using > addJavascriptInterface(); > but seems does not work, it always display "failure"; > java code: > public class WebTest extends Activity { > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > > WebView webview = new WebView(this); > webview.getSettings().setJavaScriptEnabled(true); > > webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); > webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); > webview.setClickable(true); > TestJs ts = new TestJs(); > webview.addJavascriptInterface(ts, "test"); > > webview.loadUrl("file:///data/1.html"); > > setContentView(webview); > > }} > > public class TestJs { > > public int incr(int num){ > return num+1; > > } > } > > html: > <html> > <head> > <script type="text/javascript"> > function loader() { > document.write("begin"); > document.write("<p>"); > document.write(window.test); > document.write("<p>"); > if(window.test){ > document.write("success"); > document.write("<p>"); > document.write(test.incr(100));}else{ > > document.write("failure"); > document.write("<p>"); > > } > } > > </script> > </head> > <body onload="loader()"> > </body> > </html> > > Thanks in advance for your help! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---