├── .gitignore
├── src
└── com
│ └── simonmacdonald
│ ├── .DS_Store
│ └── cordova
│ ├── .DS_Store
│ └── plugins
│ ├── .DS_Store
│ └── TelephoneNumber.java
├── www
└── telephonenumber.js
├── plugin.xml
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 |
--------------------------------------------------------------------------------
/src/com/simonmacdonald/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/macdonst/TelephoneNumberPlugin/HEAD/src/com/simonmacdonald/.DS_Store
--------------------------------------------------------------------------------
/src/com/simonmacdonald/cordova/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/macdonst/TelephoneNumberPlugin/HEAD/src/com/simonmacdonald/cordova/.DS_Store
--------------------------------------------------------------------------------
/src/com/simonmacdonald/cordova/plugins/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/macdonst/TelephoneNumberPlugin/HEAD/src/com/simonmacdonald/cordova/plugins/.DS_Store
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/plugin.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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>