There is a very important concept in Cordova: plugins .
The plug-in provides an interface to access the Cordova core API.
Plug-ins are additional code that provides the interface to access native components. In general, you will need to add some plugins to start Cordova device-level features.
Plugins are provided by the official and community, can be found on Plugins.cordova.io, and of course can be searched on the command line for plugins.
Since 3.0, Cordova has all of the device's APIs as plug-ins and is set to not start by default.
So, how do you add plugins? Two different ways.
The first is to use the CLI command line.
The second is to use lower-level command-line Plugman.
The difference between the two is that Plugman can only add one platform plugin at a time, and the CLI command line adds plug-ins for all platforms . So if you're only working on a single platform, it's more reasonable to use Plugman.
To add a plug-in using CLI command line:
1. Add Plugins
tr>
1 |
cordova plugin add org.apache.cordova.camera |
2. Remove Plugins
tr>
1 |
cordova plugin rm org.apache.cordova.camera |
3. View currently existing plugins
4. Search for plugins by keyword
tr>
1 |
cordova plugin search bar code |
5. Many plugins are available in the community, but if it is not registered to Registry.cordova.io, you can add it through the warehouse address
tr>
1 |
cordova plugin add Https://github.com/apache/cordova-plugin-console.git
|
To add a plugin using Plugman:
First you need to install Plugman
tr>
1 |
npm install-g plugman |
1. Add a plugin
1 |
plugman--platform <ios|amazon-fireos|android|blackberry10|wp7|wp8>--project < directory>--plugin <name|url|path> [--plugins _dir <directory>] [--www <directory>] [--variable <name>= <value> [-- Variable <name>= <value> ... ]
|
Add a plugin to a Cordova project via the Plugman command line. You must specify at least the platform information, Cordova the project location.
Name: The directory names of the plugins. It must be present in the Plugins_dirpath path or registered in the Cordova.
URL: A URL that begins with "/http" or "git://", pointing to a legitimate Git clone repository, which should contain a plugin.xml file, and the contents of the repository can be copied to the Plugins_dir path.
Path: A path to a directory containing a legitimate plug-in (containing a plugin.xml file). The contents of this path can be copied to Plugins_dir. Other parameters:
plugin_dir: The default is to point to/cordova/plugins, or it can be any subdirectory that contains each acquired plug-in.
www: Default to the project's WWW directory, but you can also point to the application Web asserts directory for the Cordova project.
variable: Allows certain variables to be specified at installation time, which is necessary for some plugins to require API key or other user-defined parameters.
Here is the installation command line to add the battery status plug-in
1 |
plugman-d--platform android--project Myproject–plugin Org.apache.cordova.battery-status |
The-D or-debug parameter will help you print out internal debugging information to help you track specific information.
2. Delete a plugin
Plugman--uninstall--platform <ios|amazon-fireos|android|blackberry10|wp7|wp8>--project <directory>-- Plugin <id> [--www <directory>] [--plugins_dir <directory>]
Cordova Discovery Tour Series (ii)