Cordova Android Project Custom plugin and use (i)

Source: Internet
Author: User

--New Cordova project Cordova Create Myproj com.myproj.test mytestproj--add platform and device CD Myproj Cordova platform add Android Cordova   Platform Add iOS Cordova plugin add org.apache.cordova.device--then open the project directory this way config: application configuration information platforms: App supported platform directory      Plugins: Installed plug-in directory Www:web Engineering directory we developed plug-ins to add custom plugins to the plugins directory, create a Extendinfo folder with the following structure: Extendinfo |-src |                 |-android |      |-extendinfo.java |          |-ios |-www | |-extendinfo.js |-plugin.xml src: corresponding to different platforms www: put our javascript plugin.xml: Plugin config file here is Plugin.xml
<?XML version= "1.0" encoding= "Utf-8"?><pluginID= "Com.myproj.test"version= "0.0.1"xmlns= "http://apache.org/cordova/ns/plugins/1.0"xmlns:android= "Http://schemas.android.com/apk/res/android">    <name>Extendinfo</name>    <Description>Description</Description>    <Js-modulename= "ExtraInfo"src= "Www/extendinfo.js">        <clobbersTarget= "Cordova.plugins.ExtendInfo"/>    </Js-module>    <Platformname= "Android">        <Config-fileParent="/*"Target= "Res/xml/config.xml">            <featurename= "Extendinfo">                <paramname= "Android-package"value= "Com.myproj.test.ExtraInfo"/>            </feature>        </Config-file>        <Source-filesrc= "Src/android/extendinfo.java"Target-dir= "Src/com/myproj/test"/>    </Platform></plugin>

which

ID: The identity of the plug-in, that is, the ID that is published to Plugins.cordova.io name: plug-in Name Description: Description Js-module: Corresponding to our JavaScript file, the SRC attribute points to: Www/extendinfo.js Platform: Support platform. This is Android only.
<Config-fileParent="/*"Target= "Res/xml/config.xml">            <featurename= "Extendinfo">                <paramname= "Android-package"value= "Com.myproj.test.ExtraInfo"/>            </feature>        </Config-file>        <Source-filesrc= "Src/android/extendinfo.java"Target-dir= "Src/com/myproj/test"/>

This is the configuration information for the plugin, which will be added to the Android project's Res/xml/config.xml file, and the Extendinfo.java under our Src/android/will be copied to the Android project package. Extendinfo.js content is as follows:
var exec = require (' cordova/exec 'function(success, error) {    "Extendinfo", " Getextra ", []);};

Extendinfo.java content is as follows:

 Public classExtendinfoextendsCordovaplugin {@Override Public BooleanExecute (String action, Jsonarray args, Callbackcontext callbackcontext)throwsjsonexception {activity Activity= This. cordova.getactivity (); if(Action.equals ("Getextra")) {Intent I=activity.getintent (); if(I.hasextra (Intent.extra_text)) {callbackcontext.success (I.getstringextra (Intent.extra_text)); } Else{callbackcontext.error (""); }            return true; }        return false; }}

Here, our plugin is written OK. Add the plugin by using the following command: Cordova plugin add extendinfo so our plugin is added to the project-use Eclipse to open the project, we will find the directory under assets does not show us click Open this TXT file, follow the steps to  Display, and Res/config.xml can also be displayed. At this point, we have added our custom plugin information in CONFIG. src=, the content of the "index.html" point is assets/www/index.html click to run, specific custom plug-in application to see the next article.

Cordova Android Project Custom plugin and use (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.