All Projects → RootSoft → Create-a-custom-Cordova-plugin

RootSoft / Create-a-custom-Cordova-plugin

Licence: Apache-2.0 license
How to create a custom cordova plugin and bridge it between your native code and a new or existing Cordova project

Projects that are alternatives of or similar to Create-a-custom-Cordova-plugin

cordova-plugin-zeep
Zip compression/decompression for the cordova/phonegap platform
Stars: ✭ 27 (-15.62%)
Mutual labels:  cordova, cordova-android, cordova-plugin
cordova-plugin-webpack
Integrate webpack into your Cordova workflow.
Stars: ✭ 61 (+90.63%)
Mutual labels:  cordova, cordova-android, cordova-plugin
cordova-plugin-flurryanalytics
Adds support for all that Flurry Analytics flavored goodness to your Cordova based apps
Stars: ✭ 23 (-28.12%)
Mutual labels:  cordova, cordova-android, cordova-plugin
cordova-gmv-barcode-scanner
A Cordova barcode scanning plugin based on the Google Mobile Vision library for iOS & Android.
Stars: ✭ 48 (+50%)
Mutual labels:  cordova, cordova-android, cordova-plugin
cordova-plugin-android-window-background
Simple Cordova plugin to set Android window background on start-up 🎨 🍭
Stars: ✭ 15 (-53.12%)
Mutual labels:  cordova, cordova-android, cordova-plugin
Cordova Broadcaster
Cordova Plugin to allow message exchange between javascript and native (and viceversa)
Stars: ✭ 104 (+225%)
Mutual labels:  cordova, cordova-plugin
Wifiwizard2
A Cordova plugin for managing Wifi networks (new version of WiFiWizard) - Latest is version 3+
Stars: ✭ 106 (+231.25%)
Mutual labels:  cordova, cordova-plugin
cordova-plugin-purchases
Cordova in-app purchases and subscriptions made easy.
Stars: ✭ 52 (+62.5%)
Mutual labels:  cordova, cordova-plugin
Cordova Plugin Touch Id
💅 👱‍♂️ Forget passwords, use a fingerprint scanner!
Stars: ✭ 209 (+553.13%)
Mutual labels:  cordova, cordova-plugin
Cordova Plugin Stripe
A Cordova plugin that lets you use Stripe's Native SDKs for Android and iOS.
Stars: ✭ 90 (+181.25%)
Mutual labels:  cordova, cordova-plugin
Cordova Plugin Wkwebview File Xhr
Cordova Plugin for WebView File XHR
Stars: ✭ 116 (+262.5%)
Mutual labels:  cordova, cordova-plugin
cordova-study
📱 Cordova学习记录,Cordova插件的使用,热更新、media、device、集成x5内核等等。
Stars: ✭ 19 (-40.62%)
Mutual labels:  cordova, cordova-plugin
Unityionicintegration
A guide to integrating Unity 3D content into an Ionic app and sending messages between them (for Android & iOS)(tested with Vuforia plugin)
Stars: ✭ 94 (+193.75%)
Mutual labels:  cordova, cordova-plugin
Google Analytics Plugin
Cordova Google Analytics Plugin for Android & iOS
Stars: ✭ 90 (+181.25%)
Mutual labels:  cordova, cordova-plugin
Cordova Plugin Add Swift Support
🔨 Swiftify your Cordova app !
Stars: ✭ 108 (+237.5%)
Mutual labels:  cordova, cordova-plugin
Cordova Plugin Remote Injection
DEPRECATED: Cordova plugin to allow a remote site to interact with cordova's javascript APIs when loaded within a cordova app.
Stars: ✭ 90 (+181.25%)
Mutual labels:  cordova, cordova-plugin
Cordova Plugin Audioinput
This iOS/Android Cordova/PhoneGap plugin enables audio capture from the device microphone, by in near real-time forwarding audio to the web layer of your application. A typical usage scenario for this plugin would be to use the captured audio as source for a web audio node chain, where it then can be analyzed, manipulated and/or played.
Stars: ✭ 137 (+328.13%)
Mutual labels:  cordova, cordova-plugin
cordova-plugin-example
Example Cordova plugin for iOS and Android to support blog post.
Stars: ✭ 15 (-53.12%)
Mutual labels:  cordova-android, cordova-plugin
cordova-fonts
Cordova plugin for enumerating fonts on a mobile device
Stars: ✭ 14 (-56.25%)
Mutual labels:  cordova, cordova-plugin
ZeroConf
ZeroConf plugin for Cordova/Phonegap 3.0
Stars: ✭ 39 (+21.88%)
Mutual labels:  cordova-android, cordova-plugin

Custom Cordova Plugin


This guide shows you how to create a custom cordova plugin and bridge it between your native android code and your new or existing Cordova project.

First of all make sure you got everything installed and the latest version that you need to create your own cordova project. (npm, Cordova CLI, etc)

Cordova


Create a new cordova project

If you already have an existing cordova project, you can skip this step. Create a new cordova project using CLI, from scratch or using your desired IDE e.g. (WebStorm new project -> PhoneGap/Cordova App).

$ cordova create LogicLinkApp com.endare.logiclinkplugin

Add the platform to your cordova project

Add the platforms that you want to target your app. We will add the 'android' platform and ensure they get saved to config.xml and package.json:

$ cordova platform add android

Plugman


Install Plugman

Install Plugman globally using the following command:

$ npm install -g plugman

You can use the plugman help command to display the help file and documentation about plugman.

Create a plugin

Navigate to the folder where you want to create your plugin.

$ plugman create --name <pluginName> --plugin_id <pluginID> --plugin_version <version> [--path <directory>] [--variable NAME=VALUE]

This will create a folder in your specified path with the plugin name you defined.

Example:

$ plugman create --name LogicLinkPlugin --plugin_id cordova-plugin-logiclinkplugin --plugin_version 0.0.1

Add the platform to your plugin

This generates a generic template for your plugin for your desired platform.

$ plugman platform add --platform_name android

Add a Package.JSON file

Creates a package.json file in the plugin based on values from plugin.xml.

 $ plugman createpackagejson <directory>

You can use . for your current directory.

Here you will need to enter some information about your plugin.

Install the plugin

Now we install the plugin in our existing Cordova project for our platform. The code below is specific for adding a plugin to an Cordova-Android project.

$ plugman install --platform android --project platforms/android --plugin ../LogicLinkPlugin/

Note! This will copy your existing plugin to the src folder of your desired platform. Do not edit plugin files in your Cordova Project! Whenever you make changes to your plugin, you have to uninstall the plugin using:

$ plugman uninstall --platform android --project platforms/android --plugin ../LogicLinkPlugin/

and reinstall it with the plugman install command above.

Usage


The JavaScript interface provides the front-facing interface, making it perhaps the most important part of the plugin. You can structure your plugin's JavaScript however you like, but you need to call cordova.exec to communicate with the native platform, using the following syntax:

Here is how each parameter works:

  • function(winParam) {}: A success callback function. Assuming your exec call completes successfully, this function executes along with any parameters you pass to it.

  • function(error) {}: An error callback function. If the operation does not complete successfully, this function executes with an optional error parameter.

  • service: The service name to call on the native side. This corresponds to a native class, for which more information is available in the native guides listed below.

  • action: The action name to call on the native side. This generally corresponds to the native class method. See the native guides listed below.

  • [/ arguments /]: An array of arguments to pass into the native environment.

Go to the plugin.xml file in your Plugin project and look for the value of the <clobbers target="value">. Copy this value. This will be used in the Cordova Application to bridge between the Cordova and Android application

In your <pluginname>.js file, you can write your own methods by extending the exports function with a new exec.

exports.coolMethod = function(arg0, success, error) {
    exec(success, error, "LogicLinkPlugin", "coolMethod", [arg0]);
};

Add the following code to wherever you need to call the plugin functionality:

cordova.plugins.<PluginName>.<method>();

For example:

function testPlugin() {
    cordova.plugins.LogicLinkPlugin.coolMethod("coolMethod", function(response){
        console.log(response);
    }, function(error){
        console.log(error);
    });
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].