concept plugin in category cordova

This is an excerpt from Manning's book Apache Cordova in Action.
The plugins folder —Where, you guessed it, plugins will be stored. Plugins are how Cordova applications do their magic—like accessing the camera. You’ll learn more about plugins in chapter 4.
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.
Figure 4.1. Cordova plugins stand between and facilitate communication between JavaScript and the device.
![]()
Plugins are code written in native languages (Objective-C, Java, and so forth) that provide a hook that can be called by a JavaScript file loaded by your Cordova application. They allow your JavaScript code to do things it wouldn’t normally be able to do. There’s no camera.getPicture() function available to mobile browsers, but by using plugins, Cordova provides support for doing just such a thing. The Cordova version (and you’ll see a full example later in this chapter) looks like so: navigator.camera.getPicture(). This only works because the plugin behind the camera support adds this functionality.
For a plugin to work across multiple platforms, multiple versions of the plugin are built. Taking the Camera plugin feature as an example, someone must create native code for Android, Windows Phone, iOS, and other platforms that can access the device camera. Once that’s done, one JavaScript API can be used so your code will work the same (or close enough) on all those platforms. Luckily there are quite a few plugins available for you to use in your Cordova projects.