PDA

View Full Version : Issue with Android Javascript interface



uzairkhan
3 Mar 2011, 12:59 PM
I am trying to figure out a way to communicate from a Sencha Touch app to an Android client using Android's ability to expose a javascript interface on a webview.

What I am doing is viewing my Sencha Touch app within a Webview from an Android app and then exposing a javascript interface to allow the Sencha Touch app to call methods from my interface in the Android app. The following is the code I am using:

webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new DemoJavaScriptInterface(), "demo");


I am able to to then call this javascript interface view the following HTML command in a sample HTML file and it works just fine using the following HTML code:
<input id="theButton" type=button value="Click me !" onClick="window.demo.callBackFromJS()">

FYI callBackFromJS() is a method in my DemoJavaScriptInterface.

I am trying to achieve the same in a Sencha app through a handler call within a xtype via the following code:
{
text: 'Call Back to Android',
handler: window.demo.callBackFromJS
}

However this does not seem to work properly. Anyone know how I can access the demo javascript interface this way?

norabora
3 Mar 2011, 4:05 PM
try this.

{
text: 'Call Back to Android',
handler: function() {
window.demo.callBackFromJS();
}
}