1

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

Community
  • 1
  • 1
Hodaya Shalom
  • 4,327
  • 12
  • 57
  • 111

2 Answers2

4

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. :)

Jeremy Roman
  • 16,137
  • 1
  • 43
  • 44
Andreas Gustafsson
  • 321
  • 3
  • 5
  • 16
1

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");
    }
}
Fr0g
  • 252
  • 1
  • 9