phonegap plugins joe bowser [email protected]
TRANSCRIPT
PhoneGap PluginsJoe Bowser
About PhoneGap
● PhoneGap is an HTML5 app platform that allows you to author native applications with web technologies and get access to APIs and app stores
● Exists on iPhone, Android, Blackberry WebWorks, Windows Mobile 7, Symbian, WebOS and Samsung bada
● Allows developers to get the majority of their app developed quickly
PhoneGap Application Examples
● Android Examples:● National Film Board of
Canada (NFB Films)● DiaryMobile● Logitech Squeezebox● Registered Nurses of
Ontario (RNAO)● Vimeo Mobile (by
Dreamcarved)
NFB Application (Honeycomb)
Why plugins exist
● When working on projects (including the NFB project), we needed to extend PhoneGap
● The NFB Application has these Native Features● Video Player● NFB Desktop Widget● Native Menus
● We had to extend PhoneGap with native code to step in where the browser stopped working
Do I need to write a plugin?
● PhoneGap Android currently supports:● Geolocation (HTML5 replacement)● Accelerometer● Compass● Camera● Contacts● FileReader/FileWriter● Network Status/Reachability● Storage
Do I need to write a plugin (cont)?
● Temperature● File Transfer● Capture● Battery
● These features are themselves plugins and will become more modular
● If you need features, other than this, or if the web performance would be too slow, you need a plugin
PhoneGap Plugins?
● There is a phonegap-plugins repository with various plugins
● Plugins are written in the native language of the platform (iOS plugins are in Objective-C, Android plugins are written in Java)
● Plugins consist of a native library or source file, and a Javascript interface file
● Plugins are the preferred way of extending PhoneGap without running into errors
Examples of Plugins
● Found at https://github.com/phonegap/phonegap-plugins
● WebIntents ● NFC ● PayPal● TTS● Barcode Scanner● Google Analytics● Video Player
Installing a Plugin on Android
● Create a PhoneGap Project● Copy the Java files to where their package
would be● Edit the resource file res/xml/plugins.xml● Build the Application
Writing an Android Plugin
● Android plugins are written in Java● Some people are fine with this and use vim to
write Java● I am not one of these people. I still use Eclipse
to do Java Development (I write all my other code in vim)
● We're going to work on a plugin LIVE!
The Live Demo
Warning:Live Coding will be involved
(sort-of)http://bit.ly/pg_android_tutorial
Summary of the Demo
● Get PhoneGap-Android Source● Create a project to develop the plugin● Create a class to extend the Plugin object● Implement native methods in that package● Write a JS layer to use PhoneGap.exec()
Conclusion
● PhoneGap plugins are useful when you need the following● Native Functionality that isn't in any W3C
specification● Optimized APIs for when Javascript today just isn't
the right choice (Cryptography, for example)● Integrating 3rd Party APIs for Android to add a more
smooth user experience
For more information
● PhoneGap website: http://phonegap.com● IRC: #phonegap on irc.freenode.net● Twitter: @phonegap● Code Examples from this presentation:
● http://bit.ly/pg_android_tutorial