Questions tagged [phonegap-plugins]

A Cordova (PhoneGap) plugin bridges a bit of functionality between the WebView powering a Cordova application and the native platform the Cordova application is running on.

A Cordova (formerly PhoneGap, see ) plugin bridges a bit of functionality between the WebView powering a Cordova application and the native platform the Cordova application is running on. Plugins are composed of a single JavaScript interface used across all platforms, and native implementations following platform-specific plugin interfaces that the JavaScript will call into.

JavaScript

The entry point for any plugin is JavaScript. The reason developers use Cordova is so they can use and write JavaScript, not Objective-C, not Java, not C#. The JavaScript interface for your plugin is the front-facing and arguably most important part of your Cordova plugin.

You can structure your plugin’s JavaScript however you like. The one thing you must use to communicate between the Cordova JavaScript and native environments is the cordova.exec function. Here is an example:

cordova.exec(function(winParam) {}, function(error) {}, "service",
             "action", ["firstArgument", "secondArgument", 42, false]);

The parameters explained in more detail as follows:

  1. function(winParam) {} - Success function callback. Assuming your exec call completes successfully, this function will be invoked (optionally with any parameters you pass back to it)
  2. function(error) {} - Error function callback. If the operation does not complete successfully, this function will be invoked (optionally with an error parameter)
  3. "service" - The service name to call into on the native side. This will be mapped to a native class. More on this in the native guides below
  4. "action" - The action name to call into. This is picked up by the native class receiving the exec call, and, depending on the platform, essentially maps to a class's method. For more detail please check out the native guides located at the end of this article.
  5. [/* arguments */] - Arguments to get passed into the native environment

Native

Once you have defined a JavaScript for your plugin, you need to complement it with at least one native implementation.

For example, in , this native implementation would include doing the following:

  1. Creating a .h and .m class for the plugin
  2. Registering the class name in the Cordova.plist file
  3. Creating the function we called in the javascript as one of the instance methods of that class
  4. Handling our callback situations (if javascript expected a callback).

Further Reading

Links to learn more about the various platforms follow:

4204 questions
10
votes
1 answer

Phonegap app: Problems with Facebook login via native SDK or via CordovaWebView

Our project We have one responsive website (based on Meteor.js) for our product. The user authentication will be done with Facebook Logins. To have a store presents, we created Phonegap apps for IOS and Android. This apps basically load our website…
tstuber
  • 352
  • 2
  • 14
10
votes
4 answers

How to catch exit app event?

Hy! I need to catch the exit app event in my phonegap application. Actually I want to trigger a looseLife() function if the player tries to cheat and exit the app with minimize and exit from task manager while he already started a new lvl. If he…
10
votes
4 answers

PhoneGap - Open external application

I am developing a PhoneGap App, All what I need is to open an external application. e.g. my app namespace is com.demo.app1 and I need to open the com.demo.app2 application, Is this feasible ? I am using PhoneGap 3.3 I found that there is many…
amd
  • 20,637
  • 6
  • 49
  • 67
10
votes
2 answers

Plugin not found, or is not a CDVPlugin. Check your plugin mapping in config.xml

I have declared my plugin file for iOS inside plugin.xml like so:
Aras
  • 5,878
  • 9
  • 49
  • 76
10
votes
3 answers

Phonegap Build Config.xml Malformed

If I add a plugin to the config.xml and upload my project, the config appears to be malformed.
marcel
  • 3,231
  • 8
  • 43
  • 76
10
votes
5 answers

Playing video in PhoneGap/Cordova-app for iOs and Android

I need to play video in an app that's built on PhoneGap 2.7. Is it possible to make this work for both iOs and Android - covering most of todays Android devices? Preferably the video file should be played from a local location, so that the video…
Publicus
  • 1,550
  • 7
  • 18
  • 33
10
votes
3 answers

Android reverse tethering over usb (not root)

I'm developing an enterprise app in PhoneGap, and I want to work offline with some data, and through a plugin (with code written in Java) send the processed data back over the LAN Network (when this were detected), but I need some code samples to…
Kristian Damian
  • 1,360
  • 3
  • 22
  • 43
10
votes
1 answer

Uncaught TypeError: Object # has no method 'exec' at file:///android_asset/www/index.html
using PhoenGap 2.2.0 Executed \bin\create C:\Temp\Test com.test Test Had following output Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved. Creating new android project... Building jar…
javadevg
  • 644
  • 1
  • 7
  • 13
10
votes
3 answers

Cordova 2.2.0 on iOS - RequireJS won't load Cordova correctly

I'm currently developing a webapp using Cordova (Phonegap), Backbone and JQtouch. Among other things, I need to add events in the user calendar. Everything works fine on Android. I'm still using Cordova 2.0.0. (I didn't upgrade to the latest…
Ganesh
  • 206
  • 1
  • 2
  • 8
9
votes
2 answers

Cordova Phonegap local notifications not working

I wanted to first say this is a really nice plugin (https://github.com/katzer/cordova-plugin-local-notifications) but having some difficulties getting it working. I am using an Android and Phonegap CLI. I have tried both CLI 5.0 and now Phonegap…
TheBlackBenzKid
  • 26,324
  • 41
  • 139
  • 209
9
votes
2 answers

Cordova default config.xml URI is not registered

I'm trying to build an android app by using Cordova. However, after I created the project, added platform android, and import it into Android Studio. I met some problems with the config.xml. I didn't change anything but I still get this error. It…
TommyQu
  • 509
  • 5
  • 18
9
votes
2 answers

Change orientation of ios keyboard?

Im using phonegap.build and i need to do the following on my game app: The game is forced to landscaped mode at all time, and it has no canvas version of it, this is ios and android only game, and i use it with phonegap. With the facebook-connect…
9
votes
1 answer

phonegap app with Smart Card integration

I have a phonegap/cordova app that I want to secure with Precise Biometric's Smart Card Tactivo reader. I am very new to Smart card integration, and Precise Biometrics does not seem to have a very informative documentation. However I have found that…
now_world
  • 940
  • 7
  • 21
  • 56
9
votes
3 answers

During Installation Cordova (PhoneGap) I am getting warning like "npm WARN engine Cordova-js@3. 8.0: wanted:..."

I want to develop PhoneGap application, So I am trying to install cordova on the window using the procedure mention in this link. 1. Node.js 2. git client 3. npm install npm -g I use above step-3,(Please see) to get rid from this warning, did not…
Neelabh Singh
  • 2,600
  • 12
  • 51
  • 88
9
votes
4 answers

Phonegap Network Connection - Cannot read property 'type' of undefined

I have been searching around all day for the answer to this and the Google-sphere has not provided any answers. I have tried everything I know how to do and worked through the suggested solutions and answers and nothing has worked. In a nutshell I…