├── .gitignore ├── README.md ├── plugin.xml ├── src └── com │ └── simonmacdonald │ ├── .DS_Store │ └── cordova │ ├── .DS_Store │ └── plugins │ ├── .DS_Store │ └── TelephoneNumber.java └── www └── telephonenumber.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TelephoneNumber plugin for Phonegap # 2 | 3 | The telephone number plugin allows you to retreive the devices phone numberfrom your PhoneGap application. 4 | 5 | ## Adding the Plugin to your project ## 6 | 7 | Using this plugin requires [Android PhoneGap](https://github.com/apache/incubator-cordova-android). 8 | 9 | 1. To install the plugin, copy the www/telephonenumber.js file to your project's www folder and include a reference to it in your html file after cordova.js. 10 | 11 | <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
12 | <script type="text/javascript" charset="utf-8" src="telephonenumber.js"></script> 13 | 14 | 2. Create a directory within your project called "src/com/simonmacdonald/cordova/plugins" and copy src/com/simonmacdonald/cordova/plugins/TelephoneNumber.java into it. 15 | 16 | 3. In your res/xml/config.xml file add the following line: 17 | 18 | <plugin name="TelephoneNumber" value="com.simonmacdonald.cordova.plugins.TelephoneNumber"/> 19 | 20 | ## Using the plugin ## 21 | 22 | You create a new object that represents the plugin using cordova.require. Then you can call the 'get' method on that object providing a success callback which will be called with a result value that is the devices phone number. 23 | 24 |
25 |   /**
26 | 	* get the devices phone number.
27 |     */
28 |   get(success, failure)
29 | 
30 | 31 | Sample use: 32 | 33 | var telephoneNumber = cordova.require("cordova/plugin/telephonenumber"); 34 | telephoneNumber.get(function(result) { 35 | console.log("result = " + result); 36 | }, function() { 37 | console.log("error"); 38 | }); 39 | 40 | 41 | ## RELEASE NOTES ## 42 | 43 | ### December 6, 2012 ### 44 | 45 | * Initial release 46 | 47 | 48 | ## BUGS AND CONTRIBUTIONS ## 49 | 50 | 51 | ## LICENSE ## 52 | 53 | This plugin is available under the MIT License (2008). 54 | The text of the MIT license is reproduced below. 55 | 56 | --- 57 | 58 | ### The MIT License 59 | 60 | Copyright (c) <2012> 61 | 62 | Permission is hereby granted, free of charge, to any person obtaining a copy 63 | of this software and associated documentation files (the "Software"), to deal 64 | in the Software without restriction, including without limitation the rights 65 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 66 | copies of the Software, and to permit persons to whom the Software is 67 | furnished to do so, subject to the following conditions: 68 | 69 | The above copyright notice and this permission notice shall be included in 70 | all copies or substantial portions of the Software. 71 | 72 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 73 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 74 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 75 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 76 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 77 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 78 | THE SOFTWARE. 79 | -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | TelephoneNumber 12 | This plugin allows your to get hold of the telephone number from an android device 13 | Simon MacDonald, updated to Cordova 3 by Russell Stather 14 | android, phone number 15 | MIT 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/com/simonmacdonald/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/macdonst/TelephoneNumberPlugin/20321d1ec7046d0cafeecac2bcef2e28d9510827/src/com/simonmacdonald/.DS_Store -------------------------------------------------------------------------------- /src/com/simonmacdonald/cordova/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/macdonst/TelephoneNumberPlugin/20321d1ec7046d0cafeecac2bcef2e28d9510827/src/com/simonmacdonald/cordova/.DS_Store -------------------------------------------------------------------------------- /src/com/simonmacdonald/cordova/plugins/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/macdonst/TelephoneNumberPlugin/20321d1ec7046d0cafeecac2bcef2e28d9510827/src/com/simonmacdonald/cordova/plugins/.DS_Store -------------------------------------------------------------------------------- /src/com/simonmacdonald/cordova/plugins/TelephoneNumber.java: -------------------------------------------------------------------------------- 1 | package com.simonmacdonald.cordova.plugins; 2 | 3 | import org.apache.cordova.CallbackContext; 4 | import org.apache.cordova.CordovaPlugin; 5 | import org.apache.cordova.PluginResult; 6 | import org.json.JSONArray; 7 | 8 | import android.content.Context; 9 | import android.telephony.TelephonyManager; 10 | 11 | public class TelephoneNumber extends CordovaPlugin { 12 | 13 | public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { 14 | if (action.equals("get")) { 15 | TelephonyManager telephonyManager = 16 | (TelephonyManager)this.cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE); 17 | String result = telephonyManager.getLine1Number(); 18 | if (result != null) { 19 | callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); 20 | return true; 21 | } 22 | } 23 | callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR)); 24 | return false; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /www/telephonenumber.js: -------------------------------------------------------------------------------- 1 | cordova.define("cordova/plugin/telephonenumber", 2 | function(require, exports, module) { 3 | var exec = require("cordova/exec"); 4 | var TelephoneNumber = function () {}; 5 | 6 | var TelephoneNumberError = function(code, message) { 7 | this.code = code || null; 8 | this.message = message || ''; 9 | }; 10 | 11 | TelephoneNumber.NO_TELEPHONE_NUMBER = 0; 12 | 13 | TelephoneNumber.prototype.get = function(success,fail) { 14 | exec(success,fail,"TelephoneNumber", 15 | "get",[]); 16 | }; 17 | 18 | var telephoneNumber = new TelephoneNumber(); 19 | module.exports = telephoneNumber; 20 | }); 21 | 22 | if(!window.plugins) { 23 | window.plugins = {}; 24 | } 25 | if (!window.plugins.telephoneNumber) { 26 | window.plugins.telephoneNumber = cordova.require("cordova/plugin/telephonenumber"); 27 | } 28 | --------------------------------------------------------------------------------