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
94
votes
6 answers

"No Content-Security-Policy meta tag found." error in my phonegap application

After update Cordova 5.0 in my system, I create new applications. When I tested my application on a device that time I get an error in the console log: No Content-Security-Policy meta tag found. Please add one when using the Cordova-plugin-whitelist…
user4809193
82
votes
14 answers

Add entry to iOS .plist file via Cordova config.xml

I am new to the Cordova CLI. I need to perform the following steps programmatically via Cordova. In the project .plist add a new row Enter the following values in the new row: Key: GDLibraryMode Type:String (default) Value:GDEnterpriseSimulation I…
Red2678
  • 3,063
  • 2
  • 26
  • 40
65
votes
7 answers

Exit from app when click button in android phonegap?

I am new to phonegap. I have prepared one sample application. My application has 2 pages, the first page has one button, when clicked the second page will open. It is working fine using the following function callAnothePage() { …
user1651572
  • 753
  • 1
  • 7
  • 13
50
votes
9 answers

PhoneGap - Detect device type in phonegap

I'm building an application in phonegap for the three different platforms: Android, iOS And Blackberry. While doing so, I have to detect the device type so that I can manage the height and width of my app on different platforms and for different…
Preet_Android
  • 2,325
  • 5
  • 23
  • 43
46
votes
5 answers

Create a Custom AdMob Plugin for Phonegap Build (for iOS and Android)

Everything in my Phonegap Build app is working, including the Analytics and FacebookConnect plugins. However, now I would like to add AdMob ads. Phonegap Build does not provide a built-in plugin for AdMob, but according to the Phonegap Build Plugins…
Mark Rummel
  • 2,800
  • 9
  • 34
  • 49
46
votes
14 answers

How to use Google Analytics with Phonegap without a plugin?

I am making an app and I want to get analytics from the users. I tried to use the Phonegap Plugin, but I didn't have any luck trying to implement it. I was wondering if it was possible to get Google Analytics by treating the app like a normal…
Mike
  • 2,185
  • 6
  • 25
  • 39
44
votes
5 answers

Should a phonegap plugin be declared in the config.xml file?

I am a newbie in phonegap development so I have a couple of questions: 1) I am using the accelerometer plug-in. I read in the manual that i need to declare the plugin in the config.xml file in order to use it. However I noticed that even if i remove…
panipsilos
  • 2,091
  • 8
  • 34
  • 48
40
votes
14 answers

Cordova - Current working directory is not a Cordova-based project

I'm using phonegap for my mobile project. My question is why I got this error when I try to search phonegap plugin using cordova CLI? I run this command in terminal to search phonegap plugin cordova plugin search bar code Full error message Last…
Mohammad Nurdin
  • 20,761
  • 38
  • 117
  • 280
37
votes
1 answer

Concatenate and minify cordova/phonegap plugin files

I'm building a Cordova 3.5.0 application. I use grunt to build a minified web app, then I use cordova CLI and cordova hooks to build a platform specific package. I use more than 10 different plugins, some Cordova official ones and some custom. I'm…
sgimeno
  • 1,833
  • 1
  • 22
  • 35
34
votes
7 answers

Cordova InAppBrowser - How to disable URL and Navigation Bar?

I am currently building a News Aggregator App and I am using InAppBrowser for people to read the articles. Now, my questions is: Can I remove the URL and Navigation Bar? Also, can I change the "Done" button text? Please let me know... Thanks
Ganikkost
  • 2,725
  • 15
  • 40
  • 66
33
votes
6 answers

Unable to load image when selected from the gallery on Android 4.4 (KitKat) using PhoneGap Camera Plugin

I'm trying to set the source of an img tag in my app based on the image chosen from the device image gallery using the PhoneGap/Cordova Camera Plugin. It has worked previously as intended on older versions of Android (3.3) and works fine on iOS but…
CrazyEraserUK
  • 353
  • 1
  • 3
  • 11
33
votes
8 answers

What is the cordova_plugins.json file for? Cordova is requesting it at initialization

I am trying to debug what the cordova_plugins.json file is used for? I am using multiple plugins so far and I have never interacted with this file. I want to figure out why cordova makes an xhr request for this file at initialization. When looking…
Eric H
  • 1,666
  • 3
  • 15
  • 17
33
votes
5 answers

Phonegap Offline Database

I want to store some large offline data in user phone (more than 100 MB) in an encrypted database. If possible I also want to distribute the database pre-populated. I have also seen this. I know about the webdatabase thing, but because it is…
noway
  • 2,477
  • 6
  • 36
  • 59
32
votes
9 answers

Generating iOS and Android icons in Cordova / PhoneGap

I have a freshly created Cordova project with the following config.xml setup (used the instructions from http://docs.phonegap.com/en/edge/config_ref_images.md.html). I also added 2 platforms (iOS and Android). When I run either cordova run ios or…
aporat
  • 5,832
  • 5
  • 27
  • 54
32
votes
9 answers

com.facebook.sdk error 2 on iOS

I have a Phonegap app that runs on both iOS and Android. The app has a Facebook login feature which worked until a few days ago. A few of our beta testers have reported an 'The operation couldn't be completed com.facebook.sdk error 2' error. The…
saltandpepper
  • 878
  • 2
  • 10
  • 29
1
2 3
99 100