You still need to develop your own plug-ins...
My Cordova version is 4.0.0
1. Create a folder named myplugin.
1.1 create a new plugin. xml file in the myplugin folder.
1.2 create an android IOS folder in the SRC folder
2. the console. Java file in the android folder
1 package cn.debi.cordova;
2 import org.apache.cordova.CordovaWebView;
3 import org.apache.cordova.CallbackContext;
4 import org.apache.cordova.CordovaPlugin;
5 import org.apache.cordova.CordovaInterface;
6 import org.json.JSONArray;
7 import org.json.JSONException;
8 import org.json.JSONObject;
12 import android.util.Log;
13 public class Console extends CordovaPlugin {
14
15 public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
16 throws JSONException {
17 String databack=args.getString(0);
18 final String ACTIVITY_TAG="MyAndroid"; 20 if (action.equals("Consolelog")) {
21 Log.i(ACTIVITY_TAG,databack);
22 callbackContext.success(databack);
23 return true;
24 }
25 return false;
26 }
27 }
3. Create a console. js file in the WWW folder.
1 var exec = require (‘cordova / exec’);
2
3 exports.setConsole = function (messege, success, error) {
4 exec (success, error, "Console", "Consolelog", [messege]); // console is the class name of java, consolelog is the string of action
5};
4. In plugin. xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <plugin id="cn.debi.cordova" version="0.0.1"
3 xmlns="http://apache.org/cordova/ns/plugins/1.0"
4 xmlns:android="http://schemas.android.com/apk/res/android">
5 <name>Console</name>
6 <description>Description</description>
7 <js-module name="Console" src="www/Console.js">
8 <clobbers target="cordova.plugins.Console"/>
9 </js-module>
10 <platform name="android">
11 <config-file parent="/*" target="res/xml/config.xml">
12 <feature name="Console">
13 <param name="android-package" value="cn.debi.cordova.Console"/>
14 </feature>
15 </config-file>
16 <source-file src="src/android/Console.java" target-dir="src/cn/debi/cordova"/>
17 </platform>
18 </plugin>
Where
<Plugin id = "cn. Debi. Cordova" version = "0.0.1">
The ID in </plugin> can be written at will. It is the identifier of the plug-in. The version can be written at will.
6. Call the plug-in by using the plug-in method
var extraInfo = cordova.require(‘cn.debi.cordova.Console‘);
2 extraInfo.setConsole(‘cole.log‘,function(message) {
3 alert(message);
4 }, function(message) {
5 alert(message);
6 });
Here, CN. Debi. Cordova. Console in Cordova. Require ('cn. Debi. Cordova. console') is the ID in plugin. xml; console is the name in JS-module.
That is, call console. js to export the Method
~ Extrainfo. setconsole () is the method for calling the export.
7. Forgot to add the plug-in O (plugin _ plugin) O ~~
1 Cordova plugin add myplugin # directory name, which can also be the GIT address
1 cordova plugin add /your/plugin/address/myplugin
Develop your own plug-ins using CORDOVA