Makeup Of a Plugin
PhoneGap plugins consist of 2 things.
- Native Code File
If you download a plugin from somewhere, and it doesn’t have at least those two things then you are missing something. It is a fairly simple thing to do you write your native code and then write a JavasSript interface for it which executes the native code.
How Do You Execute Native Code?
Inside the exec command you will call the class from your native code, and specify a method. The PhoneGap framework will execute it and return back the information it needs to for you to do with it what you need.
What Does the Native Code Need?
What you really only need is a class that inherits from PGPlugin and has a method for you to call. Inheriting from PGPlugin is important because it can cause a lot of headaches if it isn’t, and I mean a lot.
Tell PhoneGap the Plugin Exists
Why Is It Important to Know at Least These Things
Because if you use PhoneGap you are going to need a plugin at some point, and sometimes you will want to use code which has no documentation or, very little. So knowing at least the basics of what all plugins need you can figure out problems based on error messages. Also it helps you think beyond what PhoneGap does and gives you the opportunity to extend where you need to, especially since plugins aren’t usually that complex to write.
I am having a lot of phone using PhoneGap with jQuery Mobile. It helps me create stuff very quickly, and even do some cool stuff I am not sure I would have figured out how to do after only a couple hours of playing. The biggest benefit is you can quite easily extend PhoneGap with its simple plugin system. Which makes porting to multiple platforms much nicer. Give it a shot and enjoy.