Cordova Custom Plugin Development

Source: Internet
Author: User

Just contact PhoneGap because of the various problems encountered with the environment . , so write an article hoping to save you some time .  This article is a keynote Windows system under the PhoneGap the environment to build  , in Android -based perspective . IOS users can refer to ;

  

1: First introduce the basic preparation of the environment :

1 Java JDK (http://www.oracle.com/technetwork/java/javase/downloads/index.html)

2 Android SDK http://developer.android.com/sdk/index.html

3 Node https://nodejs.org/en/

4 Sublime HTTP://WWW.SUBLIMETEXT.COM/2:

2: next start the installation of the PhoneGap:

1:phonegap official website Click

To run the command in the console:
NPM install-g phonegap (Mac using : sudo npm install-g phonegap)

wait for installation to complete after installing Cordova:

NPM install-g Cordova (Mac using : sudo npm install-g Cordova)

After installation is complete


Test Statement :

Phonegap-version

Cordova-version

3:cordova Custom Plugins

Customizing the plug-in directory structure

Here the src corresponding different platform, www put our JavaScript file, plugin.xml is the plug-in configuration file.

  

Here are some of the code for the Java file

Here's the youyunimplugin.js file.

Export

Keep talking about the very important configuration file Plugin.xml

<?xml version= "1.0" encoding= "UTF-8"?>
<!--ID: Plug-in identification--
<plugin xmlns= "http://apache.org/cordova/ns/plugins/1.0" id= "Youyun-cn-plugin-im" version= "1.0.0" >
<!--name: plug-in Names--
<name>YouYunIMPlugin</name>
<!--Description: Description Information--
<description>youyunimplugin description</description>
<author>YouYun</author>
<license>apache 2.0 license</license>
<engines>
<engine name= "Cordova" version= ">=3.0.0"/>
</engines>
<!--js-module: corresponding to our JavaScript file src: attribute point to Www/youyunimplugin.js-->
<js-module src= "Www/youyunimplugin.js" name= "Youyunimplugin" >
<clobbers target= "Youyunimplugin"/>
</js-module>
<!--platform: supported platforms--
<!--iOS--
<platform name= "ios" >
<config-file target= "config" parent= "/*" >
<feature name= "Youyunimplugin" >
<param name= "Ios-package" value= "Youyunimplugin"/>
<param name= "onload" value= "true"/>
</feature>
</config-file>
<config-file target= "*-info.plist" parent= "Yysdkconfig" >
<dict>
<key>CLIENT_ID</key>
<string>1-20082-3e1632fba5606ffd129dd9d08b8df64a-ios</string>
</dict>
<dict>
<key>SECRET</key>
<string>c5bcda37516e2c8dbd41baa2df74821c</string>
</dict>
</config-file>
<source-file src= "src/ios/libwchatsdk.a" framework= "true"/>
<source-file src= "Src/ios/include/public.der" target-dir= "include"/>
<source-file src= "src/ios/youyunimplugin.m"/>
<source-file src= "SRC/IOS/YOUYUNAPPLICATIONHANDLER.M"/>
<!--Frameworks--
<framework src= "Libz.dylib" weak= "true"/>
<framework src= "Libsqlite3.dylib"/>
<framework src= "Cfnetwork.framework"/>
<framework src= "Coretelephony.framework"/>
<framework src= "Systemconfiguration.framework"/>
<framework src= "Foundation.framework"/>
<framework src= "Uikit.framework"/>
</platform>
<!--Android--
<platform name= "Android" >
<config-file target= "Res/xml/config.xml" parent= "/*" >
<feature name= "Youyunimplugin" >
<!--package Name: Io.youyun.cordova, class name:youyunimplugin-->
<param name= "Android-package" value= "Io.youyun.cordova.YouYunIMPlugin"/>
</feature>
</config-file>
<config-file target= "Androidmanifest.xml" parent= "/manifest/application" >
<meta-data android:name= "client_id" android:value= "1-20082-3e1632fba5606ffd129dd9d08b8df64a-android"/>
<meta-data android:name= "SECRET" android:value= "c5bcda37516e2c8dbd41baa2df74821c"/>
</config-file>
<config-file target= "Androidmanifest.xml" parent= "/*" >

<supports-screens android:largescreens= "true" android:normalscreens= "true" android:smallscreens= "true" Android: Xlargescreens= "true" android:resizeable= "true" android:anydensity= "true"/>
<!--set usage rights--
<uses-permission android:name= "Android.permission.CAMERA"/>
<uses-permission android:name= "Android.permission.VIBRATE"/>
<uses-permission android:name= "Android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name= "Android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name= "Android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<uses-permission android:name= "Android.permission.READ_PHONE_STATE"/>
<uses-permission android:name= "Android.permission.INTERNET"/>
<uses-permission android:name= "Android.permission.RECEIVE_SMS"/>
<uses-permission android:name= "Android.permission.RECORD_AUDIO"/>
<uses-permission android:name= "Android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name= "Android.permission.READ_CONTACTS"/>
<uses-permission android:name= "Android.permission.WRITE_CONTACTS"/>
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/>
</config-file>
<!--Copy the jar package under the SRC path to the Libs folder on the Libs platform.
<source-file src= "Src/android/commons-fileupload-1.2.1.jar" target-dir= "Libs" ></source-file>
<source-file src= "Src/android/commons-httpclient-3.1.jar" target-dir= "Libs" ></source-file>
<source-file src= "Src/android/commons-lang-2.6.jar" target-dir= "Libs" ></source-file>
<source-file src= "Src/android/protobuf-java-2.4.1.jar" target-dir= "Libs" ></source-file>
<source-file src= "Src/android/push-sdk-android-1.0.jar" target-dir= "Libs" ></source-file>
<source-file src= "Src/android/weimi-sdk-android-1.0.0.jar" target-dir= "Libs" ></source-file>

<source-file src= "Src/android/chatapicallback.java" target-dir= "src/cn/youyun/cordova/youyunimplugin/" > </source-file>
<source-file src= "Src/android/chattype.java" target-dir= "src/cn/youyun/cordova/youyunimplugin/" ></ Source-file>
<source-file src= "Src/android/youyunchatapi.java" target-dir= "src/cn/youyun/cordova/youyunimplugin/" ></ Source-file>
<source-file src= "Src/android/youyunchatapiimpl.java" target-dir= "src/cn/youyun/cordova/youyunimplugin/" > </source-file>
<source-file src= "Src/android/youyunimplugin.java" target-dir= "src/cn/youyun/cordova/youyunimplugin/" >< /source-file>
<source-file src= "Src/android/youyuninstance.java" target-dir= "src/cn/youyun/cordova/youyunimplugin/" >< /source-file>
<source-file src= "Src/android/youyunreceivemsgthread.java" target-dir= "src/cn/youyun/cordova/youyunimplugin/" ></source-file>
<source-file src= "Src/android/youyunutil.java" target-dir= "src/cn/youyun/cordova/youyunimplugin/" ></ Source-file>
</platform>
</plugin>

How to use Plugins

Create an application

Cordova Create Hello Com.example.hello HelloWorld

Add Platform

Cordova Platform Add Android

Cordova Platform Add iOS

When you are finished, run the following command to view:

Cordova Platfrom List

Removal of Android platform support

Cordova Platform RM Android

Installing plugins

Cordova plugin Add [custom plugin directory]

Remove Plugins

Cordova plugin RM [plugin name]

Run the following command to compile the application:

Cordova Build or Cordova build Android//compile only for Andorid platform




  

Cordova Custom Plugin Development

Related Article

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.