phonegap plugins joe bowser [email protected]

15
PhoneGap Plugins Joe Bowser [email protected]

Upload: others

Post on 12-Sep-2021

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PhoneGap Plugins Joe Bowser [email protected]

PhoneGap PluginsJoe Bowser

[email protected]

Page 2: PhoneGap Plugins Joe Bowser [email protected]

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

Page 3: PhoneGap Plugins Joe Bowser [email protected]

PhoneGap Application Examples

● Android Examples:● National Film Board of

Canada (NFB Films)● DiaryMobile● Logitech Squeezebox● Registered Nurses of

Ontario (RNAO)● Vimeo Mobile (by

Dreamcarved)

Page 4: PhoneGap Plugins Joe Bowser [email protected]

NFB Application (Honeycomb)

Page 5: PhoneGap Plugins Joe Bowser [email protected]

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

Page 6: PhoneGap Plugins Joe Bowser [email protected]

Do I need to write a plugin?

● PhoneGap Android currently supports:● Geolocation (HTML5 replacement)● Accelerometer● Compass● Camera● Contacts● FileReader/FileWriter● Network Status/Reachability● Storage

Page 7: PhoneGap Plugins Joe Bowser [email protected]

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

Page 8: PhoneGap Plugins Joe Bowser [email protected]

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

Page 9: PhoneGap Plugins Joe Bowser [email protected]

Examples of Plugins

● Found at https://github.com/phonegap/phonegap-plugins

● WebIntents ● NFC ● PayPal● TTS● Barcode Scanner● Google Analytics● Video Player

Page 10: PhoneGap Plugins Joe Bowser [email protected]

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

Page 11: PhoneGap Plugins Joe Bowser [email protected]

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!

Page 12: PhoneGap Plugins Joe Bowser [email protected]

The Live Demo

Warning:Live Coding will be involved

(sort-of)http://bit.ly/pg_android_tutorial

Page 13: PhoneGap Plugins Joe Bowser [email protected]

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()

Page 14: PhoneGap Plugins Joe Bowser [email protected]

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

Page 15: PhoneGap Plugins Joe Bowser [email protected]

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