Hodaya Shalom
Hodaya Shalom

Reputation: 4417

From PhoneGap to call the JS function

I saw that you can call from JS to function of PhoneGap on the following link:

Communication between Android Java and Phonegap Javascript?

My question is if you can in the opposite way?

From PhoneGap to call the JS function

Upvotes: 1

Views: 1133

Answers (2)

Andreas Gustafsson
Andreas Gustafsson

Reputation: 321

If I were you, I would read this tutorial on how to implement a JavaScript interface on Android, and after this you should be able to call a JavaScript functions either way.

for example from your code: webViewName.loadUrl("javascript:somemethod()");

I believe you can implement this behavior in PhoneGap. Tell me if i'm wrong!

That's what i think off the top of my head. :)

Upvotes: 4

Fr0g
Fr0g

Reputation: 252

in android, the DroidGap class(one which is base class for activity for a phonegap app) provides method "sendJavascript()" to execute javascript. this methods is available for activity extending the DroidGap class, something like this -

     public class MainActivity extends DroidGap {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MainActivity.this.sendJavascript("var myInt=10;");
        super.loadUrl("file:///android_asset/www/index.html");
    }
}

Upvotes: 1

Related Questions