Skip to content

Commit ec05289

Browse files
committed
Initial commit
0 parents  commit ec05289

File tree

7 files changed

+126
-0
lines changed

7 files changed

+126
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

README.md

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
&lt;script type="text/javascript" charset="utf-8" src="cordova.js"&gt;&lt;/script&gt;<br/>
12+
&lt;script type="text/javascript" charset="utf-8" src="telephonenumber.js"&gt;&lt;/script&gt;
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+
&lt;plugin name="TelephoneNumber" value="com.simonmacdonald.cordova.plugins.TelephoneNumber"/&gt;
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+
<pre>
25+
/**
26+
* get the devices phone number.
27+
*/
28+
get(success, failure)
29+
</pre>
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> <Simon MacDonald., et. al., >
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+

src/com/simonmacdonald/.DS_Store

6 KB
Binary file not shown.
6 KB
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.simonmacdonald.cordova.plugins;
2+
3+
import org.apache.cordova.api.CallbackContext;
4+
import org.apache.cordova.api.CordovaPlugin;
5+
import org.apache.cordova.api.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+
}

www/telephonenumber.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
});

0 commit comments

Comments
 (0)