Cordova lesson 5: Add Plugins

You can modify the default generated app to take advantage of standard web technologies, but for the app to access device-level features, you need to add plugins.

A plugin exposes a Javascript API for native SDK functionality. Plugins are typically hosted on npm and you can search for them on the plugin search page. Some key APIs are provided by the Apache Cordova open source project and these are referred to as Core Plugin APIs. You can also use the CLI to launch the search page:

$ cordova plugin search camera
To add and save the camera plugin to config.xml and package.json, we will specify the npm package name for the camera plugin:

$ cordova plugin add cordova-plugin-camera
Fetching plugin "cordova-plugin-camera@~2.1.0" via npm
Installing "cordova-plugin-camera" for android
Installing "cordova-plugin-camera" for ios
Plugins can also be added using a directory or a git repo.

NOTE: The CLI adds plugin code as appropriate for each platform. If you want to develop with lower-level shell tools or platform SDKs as discussed in the Overview, you need to run the Plugman utility to add plugins separately for each platform. (For more information, see Using Plugman to Manage Plugins.)
Use plugin ls (or plugin list, or plugin by itself) to view currently installed plugins. Each displays by its identifier:

$ cordova plugin ls
cordova-plugin-camera 2.1.0 "Camera"
cordova-plugin-whitelist 1.2.1 "Whitelist"


D:\Cordova\zship>cordova plugin search geolocation

D:\Cordova\zship>cordova plugin add cordova-plugin-mauron85-background-geolocati
Installing "cordova-plugin-mauron85-background-geolocation" for android
Android Studio project detected
Subproject Path: CordovaLib
Subproject Path: app
Installing "cordova-plugin-mauron85-background-geolocation" for ios
Adding cordova-plugin-mauron85-background-geolocation to package.json
Saved plugin info for "cordova-plugin-mauron85-background-geolocation" to config

D:\Cordova\zship>cordova plugin ls
cordova-plugin-mauron85-background-geolocation 2.3.3 "CDVBackgroundGeolocation"
cordova-plugin-whitelist 1.3.3 "Whitelist"

Leave a Reply