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:

4233 questions
21
votes
6 answers

PhoneGap plugin: fastest way to transfer JSON data to native

I have been working on a PhoneGap plugin to enable WebGL, intended for publishing HTML5 games to mobile. It's called WebGLGap. However, PhoneGap's way of calling plugin code (via exec) typically involves stringifying all the parameters to JSON,…
AshleysBrain
  • 20,705
  • 15
  • 81
  • 119
19
votes
5 answers

PhoneGap 3 plugin: exec() call to unknown plugin "..."

I've been trying to upgrade a plugin to v3, and I've managed to get past the plugin loading issues, and I've managed to expose the plugin to the client environment (making changes to the way exec works, etc). But when I watch the adb logcat with adb…
Remy Sharp
  • 4,390
  • 3
  • 21
  • 38
18
votes
1 answer

ESLint like globals in TSLint

I'm using device plugin from cordova so I have a line like this let model = device.model || ""; which causes Cannot find name 'device'. error. I think with ESLint I would need to do "eslintConfig": { "globals": { "device": true } } but…
apreg
  • 617
  • 7
  • 16
18
votes
3 answers

How can I overlay a native view on top of PhoneGap's CordovaWebView in Android?

I'm building a phonegap plugin which needs to render a native UI view on top of the WebView that PhoneGap provides. In iOS this is very simple, just create the view and add it to PhoneGap's webView's scrollView. This will render the control on top…
Travis
  • 2,564
  • 4
  • 24
  • 46
18
votes
5 answers

Phonegap 3.0.0: BarcodeScanner Plugin

currently I'm trying to install the BarcodeScanner Plugin for Phonegap Version 3.0.0. I can't find any working documentation on how to install it correctly and I didn't figure it out myself. So I would really appreciate any help! Thank you in…
user1448982
  • 1,130
  • 3
  • 12
  • 22
17
votes
4 answers

Plugins are not always added after cordova add platform android and iOs

I need to run ionic platform add android/iOs few times to get the desired result. Sometimes plugins are added after first run, but usually I have to wipe out the plugins and platform directories and re-run adding the platform cycle few times until…
batanasov
  • 219
  • 1
  • 2
  • 13
17
votes
3 answers

How to copy a custom ios framework using plugin.xml on Phonegap 3

I am currently making a plugin for phonegap 3. I have a custom framework to copy using the source-file directive. In the plugin.xml I tried: but I get the error when I add the plugin to my…
poiuytrez
  • 18,348
  • 28
  • 100
  • 156
17
votes
5 answers

Phonegap 3 doesn't copy plugins to platforms folder

I'm using Phonegap3 http://phonegap.com/install/ but I'm facing an issue with plugins: After creating project using phonegap create my-app phonegap local build android then I added a camera plugin using phonegap local plugin add…
Hazem Hagrass
  • 8,566
  • 8
  • 29
  • 49
17
votes
4 answers

Inject code in inApp browser and get it's return value in the app

I am writing a phonegap app, that's starting a web app inside an inAppBrowser. I would like to get certain feedback from this web app to use it further in my phonegap app. So the user starts the web app, does some things there and upon clicking a…
Oliver
  • 195
  • 1
  • 1
  • 8
16
votes
5 answers

Cordova build returns missing plugin.xml

When i build my cordova project i get an warning message as: Missing file: /home/vijay/workspace/Repos_temp/QuickTraq_Android/plugins/nl.x-services.plugins.toast/plugin.xml Missing file: …
16
votes
5 answers

Cordova + JqueryMobile: Ajax fails with

(Have been at it for the last 6 hours) I am trying to make a phonegap/Cordova App. I am not able to make an Ajax call via the Android emulator(API ver 22, Android > 4.4). The Ajax call works on Firefox desktop but fails even on the chrome browser…
16
votes
6 answers

How to add Live Reload when using the command cordova serve?

I am using this command to open up my app in the browser: cordova serve but it does not refresh itself when I update my code. How can I do that? I have tried to use phonegap serve instead which has a live reload but it keeps sending me alerts and…
Matan Gubkin
  • 2,801
  • 5
  • 22
  • 38
16
votes
1 answer

Plugin to get the version of PhoneGap App?

I am using PhoneGap build to package my app is there any PhoneGap or 3rd Party Plugin that I can include in my config.xml to get the version of the app in the runtime? Any suggestion on best way to get the version of the App would be appriciated.
Hemantsom
  • 441
  • 2
  • 8
  • 24
16
votes
2 answers

Which local notification plugin should I be using with phonegap build?

It appears that there are four different 3rd party plugins to accomplish local notifications listed within phonegap…
robb
  • 577
  • 1
  • 5
  • 8
16
votes
1 answer

Android phonegap project spamming QTAGUID messages

I have been having this problem for a while now, and while it doesn't negatively affect my application I would like to fix it if I can. I am not really sure how to describe the problem. Basically, I have an Android PhoneGap 1.9 project, using API 15…
Jeff
  • 1,605
  • 2
  • 16
  • 26