Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
574 views
in Technique[技术] by (71.8m points)

cordova - How to add plugin to PhoneGap?

I'm confused a bit by PhoneGap documentation:

Link 1 // How add plugins using "phonegap local plugin add" command Link 2 // Tutorial about how to use camera module Link 3 // PhoneGap Plugins

I've added camera module according (1). But in (2), there is information saying that I should add

<plugin name="Capture" value="org.apache.cordova.Capture"/>

to app/res/xml/plugins.xml and edit app/AndroidManifest.xml files too.

In reference to 3), also there is information that <plugin ... /> construction is obsolete and the developer should use <gap:plugin ... />, instead.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Referencing the latest API documentation:

There are two ways to approach this, first is by using Plugman, and the other is by using CLI. The CLI approach is much simpler.

The Plugman approach:

  1. First, Plugman must be installed. Plugman is the plugin manager used by PhoneGap 3.4. To install Plugman, use the Node JS CLI and enter:

    npm install -g plugman

  2. Install the specific plugin using the plugman install command. For example plugman install --platform android --project platforms/android --plugin org.apache.cordova.device-motion. Be sure that the parameter for the --project option points directly to the platform folder, e.g. for Android, that's where the AndroidManifest.xml file is. This command automatically adds all references to the plugins to the pertinent xml files.

  3. Be sure that your HTML file references phonegap.js by the line <script type="text/javascript" charset="utf-8" src="phonegap.js"></script>.

Using CLI:

  1. Go to your app directory and enter the plugin command in the CLI. For example:

    phonegap plugin add org.apache.cordova.device-motion

    installs the accelerometer plugin.

  2. After the plugin has installed, it automatically updates all config.xml by adding the corresponding <feature> tags. Note that these updates only affect the platform-specific config.xml files. And so, the top-level config.xml file is not affected. You must manually copy and paste the <feature> tags to the top level config.xml. Otherwise, the plugins will be disabled when you run the app using phonegap run platform.

Take note that the corresponding <feature> tags can only be added to the corresponding config.xml files if your project is already ready to deploy in that specific platform.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...