Chapter 4. Using plugins to access device features
This chapter covers
- What plugins are and what they provide for Cordova projects
- How to find and evaluate plugins
- How to use the CLI to manage plugins
- How to use the deviceready event
So far you’ve concentrated on using the Cordova CLI to translate web stuff (HTML, JavaScript, and CSS) to native code. You’ve seen how to create a Cordova project and how to test it as a native application on either an emulator or a real device. The last piece of the puzzle is tapping into the rich set of device features that websites do not have access to: the filesystem, the camera, and so on. This was mentioned in chapter 3 as a problem with your simple application. This is where plugins enter the picture.
Suppose you want to write a Cordova application to access your phone’s camera and take a picture. JavaScript, by itself, doesn’t have access to the camera. One of the great features of Cordova is that it provides a mechanism to allow JavaScript to access things it normally wouldn’t be able to. This is done via plugins.
Plugins work by providing a way for your JavaScript to communicate to the device. Figure 4.1 illustrates this.