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
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
  • 543
  • 2
  • 9
  • 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
  • 757
  • 1
  • 6
  • 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,727
  • 2
  • 17
  • 29
15
votes
2 answers

Lost in hybrid app frameworks like Ionic, Cordova,

I'm currently lost with all these hybrid mobile app frameworks. They all sound awesome, but I can not find any real information about the use cases and main differences. Can someone explain them to me or provide me with great ressources, especially…
15
votes
2 answers

Adding drawable resource using Cordova

I want to add a drawable resource to my cordova project. I did add the icon and splashscreen items just fine. They get copied to my platform/android/res/drawable just fine. The problem is when I try to add another resource. How do I do that? I can't…
Jose Granja
  • 151
  • 1
  • 1
  • 3
15
votes
6 answers

Open url in webview - phonegap

I would like to know how can I open an url in the app context of embed webview. Currently this demo will open a new tab in external browser, so, not what I am expected. I am using google.com just for testing. Summary, I am looking for a functional…
user2990084
  • 2,699
  • 9
  • 31
  • 46
15
votes
2 answers

Show a website inside an ionic tab

I am working on an ionic framework based mobile application (mainly targeted for Android). My project is a tab based application. In the first tab I want to load an external website, but I can't figure it out how to do it. I tried ngCordova…
Shahab
  • 794
  • 2
  • 12
  • 23
15
votes
3 answers

SMS Phonegap 3.0 plugin for Android and iOS

I'm looking for phonegap plugins that will work with Phonegap 3.x. I need it to work in Android and iOS. It would be preferable if there was 1 plugin for both, but it's ok if there are 2 seperate plugins that I can use. It's also preferable if I…
aharris88
  • 3,560
  • 3
  • 27
  • 45
15
votes
1 answer

The Phonegap Barcode Scanner don't recognize any barcode on windows phone

I'm trying to add the Phonegap Barcode scanner plugin to my Phonegap app. I'm primarily developing for windows phone 8 but I also want to target the ios and android platforms. I managed to add the plugin correctly, but when I start the scan, my…
14
votes
2 answers

statusbar notification in android phonegap

I have a problem in status bar notification at 10 second interval.I have done with code for display it for one time by creating plugin.But I want to display it at every 10 minutes interval.So I used AlarmManager for generating notification at every…
M007
  • 580
  • 1
  • 5
  • 24
14
votes
4 answers

Geolocation plugin on Cordova 5.0.0 always return timeout expired error

I have installed Cordova 5.0.0 with these plugins: cordova plugin list cordova-plugin-device 1.0.1-dev "Device" cordova-plugin-geolocation 1.0.0 "Geolocation" cordova-plugin-globalization 1.0.0 "Globalization" cordova-plugin-inappbrowser 1.0.1-dev…
14
votes
3 answers

Set camera width and height phonegap camera

I am currently in the process of creating a mobile app that uses the Phonegap (Cordova) camera plugin. It correctly captures the image and displays it where I want to, but I can't seem to set the targetWidth and targetHeight options, as…
Matthijs
  • 3,162
  • 4
  • 25
  • 46
14
votes
1 answer

Using Invitable friends with phonegap facebook plugin

I am aware that invitable friends (https://developers.facebook.com/docs/games/invitable-friends/v2.0) requires canvas and category game. And I have also requested for user_friends permission on initial approval of the user. I have done all that and…
Saad Bashir
  • 4,341
  • 8
  • 30
  • 60
14
votes
2 answers

How to update cordova (phonegap) plugin in my project?

Anyone knows what is the proper way to update cordova plugin in my cordova/phonegap project? Some time ago I installed file plugin as: cordova plugin add org.apache.cordova.file Everything worked fine. Now I realized there is a new version of the…
Michal
  • 447
  • 1
  • 3
  • 10
14
votes
4 answers

How to get the application version and build in an iOS PhoneGap Application?

When you are setting up a PhoneGap project, you see the following: How can I get that information inside of the iOS application? Is there a way to do it with phonegap? What about a plugin? If no plugin exists, and there is a way to do it in an iOS…
andrewpthorp
  • 4,998
  • 8
  • 35
  • 56