Skip to main content

Steps To Create Cordova Plugin


  • Introduction

    • A plugin is a package of injected code that allows the Cordova webview within which the app renders to communicate with the native platform on which it runs.
    • Plugins comprise a single JavaScript interface along with corresponding native code libraries for each supported platform.
    • Due to following reason, we will go for plugin development
      • To get the native capabilities of the device in the cordova based app
      • Build the common functionality across the number of Cordova application(Reusability)













  • Prerequisites

    • For the creation of plugin you need to install plugman.
      • npm install -g plugman

  • Plugin Structure

    • Decide Plugin ID & Name
      • The plugin ID should be unique
      • Plugin name should follow the convention “cordova.plugin.[your.plugin.name]”
    • Create the structure
      • Use the following command to create the plugin with plugin ID “cordova.plugin.test” and name “Test”.
        • plugman create --name Test --plugin_id cordova.plugin.test --plugin_version 0.0.1
      • With the success of above command if check the our working directory then we got the result like
Test/
|- plugin.xml
|- src/
\- www/
  \- Test.js
  • Implement The Native Functionality

    • For each platform, you will add a folder under the src folder, also some entries in plugin.xml

    • Android Platform

      • To start with android platform please execute the following command
        • plugman platform add --platform_name android
      • With the success of above command if check the our working directory then we got the result like
Test/
|- plugin.xml
|- src/
|  \- android/
|     \- Test.java
\- www/
  \- Test.js
    • IOS Platform


      • To start with ios platform please execute the following command
        • plugman platform add --platform_name ios
      • With the success of above command if check the our working directory then we got the result like
Test/
|- plugin.xml
|- src/
|  |- android/
|  |  \- Test.java
|  \- ios/
|     \- Test.m
\- www/
  \- Test.js

    • Windows Phone Platform

      • The native code for Windows and Windows Phone 8.1+ is slightly different from other platforms. While it is possible to implement the functionality using C# or C++, the native APIs are actually available via JavaScript, and it is usually easiest that way.
      • Currently, plugman does not currently support the windows platform, So creates structure manually as follows
Test/
|- plugin.xml
|- src/
|  |- android/
|  |  \- Test.java
|  \- ios/
|     \- Test.m
|  \- windows/
|     \- Test.js

\- www/
  \- Test.js


  • References




Comments

Popular posts from this blog

What exactly means MVW design pattern ?

What is a MVW framework? The abbreviation stands for 'Model - View - Whatever'.  Well there are many different JavaScript frameworks available , all invented for the same purpose. They all try to separate the presentation logic from the business logic where JavaScript holds the model and logic, and html the presentation layer. Quick overview : You can change the model without changing the view and vice-versa Unit testing is easy These are the core benefits of using such a framework. By separating presentation and business logic changes to the code are easier to implement and take less time. Another benefit is that code can be reused from a controller thus saving more time. Angularjs makes the code also shorter in comparison to other frameworks, which improves code stability. Less code means minor potential for bugs. For several years +AngularJS was closer to MVC (or rather one of its client-side variants), but over time and thanks to many refactorings

File Upload & Download With ng-cordova File Transfer Plugin In Ionic Framework

Using the AngularJS extension set , ngCordova , with Ionic Framework and the Apache Cordova File Transfer plugin, you can easily upload files to a remote server and download files from a remote server. 1.Create the project ionic start Test blank cd Test ionic platform add android 2.Add Plugin org.apache.cordova.file-transfer https://github.com/apache/cordova-plugin-file-transfer This plugin allows you to upload and download files. This plugin defines global FileTransfer, FileUploadOptions Constructors. Although in the global scope, they are not available until after the deviceready event . Installation cordova plugin add cordova plugin add cordova-plugin-file-transfer     2.    org.apache.cordova.file             https://github.com/apache/cordova-plugin-file             This plugin implements a File API allowing read/write access to files residing on the    device.             Installation cordova plugin add cordova-pl

MEAN Stack Development with Vagrant

MEAN Stack Development with Vagrant Introduction Vagrant provides easy to configure, reproducible, and portable work environments built on top of industry-standard technology and controlled by a single consistent workflow to help maximize the productivity and flexibility of you and your team. To achieve its magic, Vagrant stands on the shoulders of giants. Machines are provisioned on top of VirtualBox , VMware, AWS, or any other provider . Then, industry-standard provisioning tools such as shell scripts, Chef, or Puppet, can be used to automatically install and configure software on the machine. Setup Virtualbox            You have to completely remove older VirtualBox versions before               installing VirtualBox-5.0 ! Display Allready Installed Packages sudo dpkg -l | grep virtualbox Uninstall VirtualBox sudo apt-get purge "^virtualbox-.*" Update the software repositories sudo apt-get update Clean up su