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

open an activity from a CordovaPlugin

I have written a CordavaPlugin derived class. public class ShowMap extends CordovaPlugin { @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if…
krasnoff
  • 825
  • 3
  • 16
  • 32
29
votes
6 answers

You are not logged in. Please log in and try again

I'm using phonegap facebook connect plugin (https://github.com/Wizcorp/phonegap-facebook-plugin) for Facebook Authentication in app. It was working till today morning. Now suddenly it stops working and gives error as below for different devices iOS…
immayankmodi
  • 6,510
  • 7
  • 31
  • 52
28
votes
2 answers

Where is the location of file created by Cordova File Plugin?

I have used Cordova File Plugin to create files on mobile device. Below is the code to create files: window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function (dir) { alert(cordova.file.dataDirectory); dir.getFile("log.txt", {…
Asieh Mokarian
  • 1,049
  • 2
  • 13
  • 27
26
votes
1 answer

Cordova PhoneGap upgrade to 5.1.1 from 2.2.0

I have Cordova application which is version 2.2.0. Now I want to upgrade, I have done upgrade part, after upgrading, application images are not display, it came blank screen. even splash screen also not came. Here is my code Now I reached to some…
Piraba
  • 6,288
  • 16
  • 79
  • 131
26
votes
16 answers

PhoneGap: Open external link in default browser (outside the app)

I'm trying to open links in Safari (on an iPhone) from a PhoneGap application. I'm using PhoneGap version 3.1.0, and use PhoneGap Build, to build the application. I have two links on the page (shown below in www/index.html). Both links open inside…
Martin
  • 2,192
  • 2
  • 28
  • 42
25
votes
3 answers

Cordova Change AndroidManifest using Config.xml file

I am in need to add some tags to the AndroidManifest.xml file which is found under platforms\android\AndroidManifest.xml As I have read the AndroidManifest.xml file gets generated on the fly and it is not advisable to edit it. So is there a plugin…
krv
  • 2,432
  • 5
  • 32
  • 73
25
votes
9 answers

Phonegap - Save image from url into device photo gallery

I'm developing phonegap application and I need to save Image from url to the Device Photo Gallery. I can't find at the Phonegap Api a way for doing it and Also I didn't find phonegap plugin for that. I need it to work with Iphone & Android Thanks a…
justtal
  • 790
  • 1
  • 7
  • 16
25
votes
3 answers

Share something to a phonegap app

Is there any way to register a phonegap app to appear in the menu of applications to share?
karacas
  • 1,836
  • 1
  • 17
  • 28
25
votes
9 answers

"'CDVPlugin.h' file not found" in Cordova as component (Cleaver)

I added Cordova as a component to my iOS project. Adding a custom plugin leads to the error, despite that the plugin works in a Cordova-only project: 'CDVPlugin.h' file not found PhoneGap / Cordova 1.7.0 installed Checked multiple times to…
Michael Schmidt
  • 2,981
  • 4
  • 31
  • 39
24
votes
7 answers

iOS status bar overlapping contents

I have built phonegap application, it works fine on android and windows. But for iOS I am facing issue as, status bar contents and page contents are mixed up therefore i unable to tap on the back button provided in header. Can any body help me…
RAKESH DADHICH
  • 306
  • 1
  • 3
  • 11
24
votes
3 answers

Error in Phonegap Application: Uncaught module cordova/plugin_list already defined

I have been trying to resolve many issues from having updated from Phonegap 2 to Phonegap 3.3 but I can't seem to fix this one. I have read from some users that uncaught module exceptions can cause imported plugins to stop functioning. I am having…
Gthoma2
  • 667
  • 1
  • 9
  • 18
23
votes
10 answers

Upgrade cordova: cannot install plugins from git urls anymore

I did a cordova/phonegap upgrade and now I cannot install plugins from git urls anymore. Anyone experienced such an issue and already solved this? $ cordova plugin add https://github.com/dawsonloudon/VideoPlayer.git Fetching plugin…
mwager
  • 661
  • 1
  • 4
  • 17
22
votes
5 answers

How to use Phonegap SoftKeyboard Plugin for Android?

I am developing an Android application using Phonegap. I need to make the softkeyboard appear programatically. I am using the SoftKeyboard plugin which is found here. Can anyone tell me how to properly include this plugin & make it work? I have…
N.B.K
  • 1,894
  • 2
  • 18
  • 34
22
votes
6 answers

Receive URL in Ionic for ios

I am using ionic framework. I'm trying to set up a way to receive a url from another app. Like, you are in browser, click share, and send the link to another app (my app). I found this cordova plugin, and have integrated it in my app. But this is…
Hitu Bansal
  • 2,081
  • 9
  • 44
  • 83
22
votes
2 answers

Asynchronous communication between Javascript and Phonegap Plugin

So, everybody knows that we make a Class extending CordovaPlugin and override the execute() and then creates a bridge between the JS and native Java (for Android). Further we use PluginResult to return the result back to the JS. So, all of this…
Anas Azeem
  • 2,750
  • 3
  • 21
  • 36