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
13
votes
3 answers

Android - phonegap error: Error parsing XML: unbound prefix

I restarted eclipse and the error changed to "error: Error parsing XML: unbound prefix" on the same line I am trying to use this plugin in my android phonegap application. It is a local notification plugin. I am getting the error in my config.xml…
Max Pain
  • 1,217
  • 7
  • 19
  • 33
13
votes
5 answers

External links in phonegap app do not open well

So I have a phonegap project with Phonegap 2.9.0 and building with PhonegapBuild. I got external links in my app, that I would like to open inapp or using the default device browser outside of my app. I am ok for both solutions. Today my app open…
Miguel Bocquier
  • 2,449
  • 5
  • 22
  • 38
13
votes
1 answer

Inter-device communication via Bluetooth using Phonegap on Android?

I'm wondering if it's possible for a Phonegap-based app on one android device to communicate with another Phonegap-based app on another device via Bluetooth? If it's possible to do this kind of thing with some native Java code for Android, then it…
DaveAlden
  • 30,083
  • 11
  • 93
  • 155
13
votes
1 answer

How to add a PhoneGap plugin and build the app with Phonegap build

We have some doubts about how to integrate phonegap plugins and then build our mobile application with phonegap build, is it possible? When you build your app with Phonegapbuild it builds up for all the supported devices, but the instructions…
Javier Hertfelder
  • 2,432
  • 4
  • 22
  • 36
13
votes
4 answers

Showing camera view inside html in android and then snap a picture

Is there a view of showing the live camera view inside html ( e.g. embedded in a div ) before we snap a picture using JavaScript? I have tried PhoneGap but it totally starts a new camera app and totally moves away from my html web app before…
Imran Omar Bukhsh
  • 7,849
  • 12
  • 59
  • 81
12
votes
2 answers

Upload a photo to Firebase Storage with Image URI

I am currently attempting to upload a photo to my Firebase app's storage in my Apache Cordova app. I currently get the photo's URI with the following code: function getPhotoFromAlbum() { navigator.camera.getPicture(onPhotoURISuccess, onFail,…
Roger99
  • 981
  • 2
  • 11
  • 42
12
votes
14 answers

cordova 3.0: Android: Connection is not defined

my first time experimenting with Apache Cordova 3.0. downloaded lib, unziped cordova-android and cordova-js and created a project: ./create ~/Documents/andriod-projects/HelloWorld com.x.HelloWorld HelloWorld - OK res/xml/config.xml
panchicore
  • 11,451
  • 12
  • 74
  • 100
12
votes
3 answers

Get absolute path to assets folder in PhoneGap

Is there a way to get the absolute path of an image in phonegap asset folder? I need the absolute path to attach the image in a mail using EmailComposer plugin. EmailComposer plugin wants an absolute path like this: …
Cesar
  • 4,076
  • 8
  • 44
  • 68
12
votes
1 answer

PhoneGap setKeepCallback - What does it?

i made a project, where i established a successfull communication from my bluetooth plugin to my javascript. From my Javascript i register a callback to my plugin that way in java: if (action.equals(ACTION_REGISTER_CALLBACK)) { …
tellob
  • 1,220
  • 3
  • 16
  • 32
11
votes
4 answers

Cordova Firebase Plugin Notification - Cannot add task ':processDebugGoogleServices' as a task with that name already exists

i'm trying to add Google Firebase Notifications on my Phonegap Cordova app, built with Ionic. I've already installed successfully a Google Plus plugin for login (i think this would be a useful info). I only need this Firebase plugin to complete my…
11
votes
2 answers

local storage vs database(SQLite) for a cordova app

I am developing a mobile app using javascript and cordova framework. My requirement is that a user enters something in the input textbox. This needs to be stored so that the user need not enter the same text again. It should be already present as a…
Ankur Bhatia
  • 996
  • 3
  • 17
  • 29
11
votes
3 answers

PhoneGap App Crash when take a new photo with Camera Plugin

I'm developing a mobile app with cordova/phonegap and I've installed Camera plugin. I am able to open the camera and click the image but after that app crashes. here is the crash log: java.lang.RuntimeException: Failure delivering result…
nitesh goel
  • 6,338
  • 2
  • 29
  • 38
11
votes
1 answer

Is mediaelement.js compatible with Phonegap?

I am building a phonegap application where i need to use video and audio streaming feature, i found that mediaelementjs seems more suitable for cross platform video and audio feature. I created one demo and its working fine on iOS & Android…
Suresh
  • 1,131
  • 1
  • 15
  • 28
11
votes
1 answer

Calling Pdf417 phonegap/cordova plugin in Ionic

I'm having trouble successfully calling the Pdf417 phonegap/cordova plugin scan function in demo mode within an Ionic application. I'm testing the plugin with Ionic View on iOS. Here is a linked Github repository containing a simplified version of…
11
votes
3 answers

How do you modify a PhoneGap / Cordova plugin and rebuild for iOS with the modification?

I am using the Cordova Splash Screen plugin (http://plugins.cordova.io/#/package/org.apache.cordova.splashscreen) and there is a bug with the current plugin that is causing the app to constantly crash. It appears the bug is documented here…
user3324565
  • 111
  • 1
  • 1
  • 3