how to add custom command instance

16 views
Skip to first unread message

grimace

unread,
Feb 9, 2010, 4:22:32 PM2/9/10
to phonegap
Is there some document that can show how to add a custom command to
gap code?

Shazron Abdullah

unread,
Feb 9, 2010, 4:46:37 PM2/9/10
to grimace, phonegap
There is an answer on the FAQ on the wiki:
http://wiki.phonegap.com/FAQ

On 2010-02-09, at 1:22 PM, grimace wrote:

> Is there some document that can show how to add a custom command to
> gap code?
>

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com

eyurdakul

unread,
Feb 10, 2010, 5:57:37 AM2/10/10
to phonegap
first define them in phonegap.js

function Myclass (){

}

Myclass.prototype.someThing = function(){
//leave these js functions empty. you will implement them in java code
}

PhoneGap.addConstructor(function() {
if (typeof navigator.accelerometer == "undefined")
navigator.myclass= new Myclass();
});

add it as contructor and go to the droidGap.java

//don't forget to define the types before you assign this
mything = new MyJavaClass(view, this);
appView.addJavascriptInterface(mything, "Myclass");
//now when you call something from javascript's Myclass, it will call
the MyJavaClass functions

But you have to define the functions in you javascript even they are
empty.

Reply all
Reply to author
Forward
0 new messages