Skip to content

TravelingTechGuy/PhoneGap-Plugin-Own-Phone-Number-Android

Repository files navigation

Android PhoneGap plugin to retrieve own phone number

This project demonstrates how to build and use a simple PhoneGap plugin for Android.
The plugin simply returns the phone’s number as a string.

Start by creating a PhoneGap project (we assume PhonGap version >= 1.0) in Eclipse, or using the PhoneGap Eclipse wizard to create one.

To implement your own plugin, follow these 4 steps:

  1. Create the plugin – add a class to your Java project (see MyPhoneGapPlugin.java)
    1. The class extends the PhoneGap Plugin class
    2. The function you need to implement is public PluginResult execute(String action, JSONArray data, String callbackId)
  2. Add to plugins file – add a line that includes the full path of your class to the plugins file (see plugins.xml)
  3. Create a JavaScript interface – implement a JavaScript interface to the plugin (see myphonenumber.js)
    1. Notice that it expects an oSuccess and onError callback functions
    2. No need for it to be too elaborate – contain your actual logic in the Java code, and any data preparation to the calling function
  4. Call your plugin – (see index.html)
    1. include the js file in the HTML head section
    2. I find it easier to create a single function that contains both oSuccess and onError callback functions, and the actual call

And that’s it. Again, if you keep the logic in the actual plugin Java code, you can more or less reuse this framework as is, while doing more in Java.

About

Android PhoneGap plugin to get the phone's number

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published