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

Issues with build.phonegap write to file

I'm trying to build a PhoneGap application through the online build service that should run on both iOS and Android, but this question focuses on the Android part. The main target of the application is to be able to access and modify the…
gion_13
  • 41,171
  • 10
  • 96
  • 108
8
votes
3 answers

Phonegap - Device Orientation in degrees & Magnetic Field

Can anyone tell me whether it is possible though Phonegap to get Android Device Orientation in degrees (angle of the phone relative to the ground)? Also, is it possible to get the Magnetic Field as well?
user1809790
  • 1,349
  • 5
  • 24
  • 53
8
votes
3 answers

Is it possible to send SMS from phonegap HTML/Javascript application using Phone SMS API?

I've been trying to play with Phonegap and created a small application in HTML/Javascript to send an SMS. I tried this code window.location.href = 'sms:XXXXXXXX06?body=Testing' which opens up a screen to manually send the sms which I want to…
codef0rmer
  • 10,284
  • 9
  • 53
  • 76
8
votes
4 answers

iOS PhoneGap 1.7.0 + Barcode Scanning Plugin issue

Has anyone managed to get the BarcodeScanning plugin for PhoneGap to work on PhoneGap 1.7.0? Barcode Scanning plugin: https://github.com/phonegap/phonegap-plugins/tree/master/iOS/BarcodeScanner The issues is that the plugin is not getting set when…
damien murphy.
  • 371
  • 2
  • 16
7
votes
3 answers

Share on Facebook / Twitter / E-mail feature using PhoneGap / jQueryMobile

I'm coding an app for iOS / WP7 / Android using PhoneGap and it has to allow the user to publish comments to its facebook wall / twitter or send it by e-mail. What is the easy way to face these tasks? any common approach? maybe a plugin? I have seen…
xus
  • 2,587
  • 8
  • 31
  • 44
7
votes
1 answer

cordova-plugin-ionic-webview - Unable to save password in HTML form despite autocomplete attribute

I am working on a Cordova (~PhoneGap, ~Ionic) App and I followed the Apple guidelines and added to autocomplete attributes to my HTML login form to ask users whether they want to save their credentials when they try to sign up. On Android the popup…
7
votes
1 answer

PhoneGap Admob, external links... Can't get either one to work

I know that there are bunch of answers here concerning PhoneGap. I've gone through all of them, and not a single solution worked. Even though, by all accounts, any one of them should. Many of the answers are so old that I doubt they are even…
durbnpoisn
  • 4,666
  • 2
  • 16
  • 30
7
votes
2 answers

Cannot postMessage from inappbrowser to Cordova application

I'm using this module (https://github.com/apache/cordova-plugin-inappbrowser) for the ability to open external links within my Cordova application. However, postMessage example from documentation doesn't work. I need the ability to be able for an…
Detuned
  • 3,652
  • 4
  • 27
  • 54
7
votes
3 answers

phonegap: how to check if gps is enabled

I want to show an alert saying that "Please turn on your GPS". How can I get GPS status using phonegap? I have used following code but I don't get any alert message if GPS is turned off. Instead nothing happens. …
user2899728
  • 2,099
  • 4
  • 16
  • 28
7
votes
1 answer

Cordova: Is there a way to detect whether Voice Dictation has ended on iOS

Please note that this question is for Cordova/PhoneGap/Hybrid apps. I have a