Created
December 6, 2012 04:25
-
-
Save macdonst/4221765 to your computer and use it in GitHub Desktop.
PhoneGap Phone Number Discoverer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<plugin name="TelephoneNumber" | |
value="com.simonmacdonald.cordova.plugins.TelephoneNumber"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<uses-permission | |
android:name="android.permission.READ_PHONE_STATE" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript" charset="utf-8" | |
src="telephonenumber.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { | |
if (action.equals("get")) { | |
TelephonyManager telephonyManager = | |
(TelephonyManager)this.cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE); | |
String result = telephonyManager.getLine1Number(); | |
if (result != null) { | |
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); | |
return true; | |
} else { | |
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, 0)); | |
return false; | |
} | |
} | |
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cordova.define("cordova/plugin/telephonenumber", | |
function(require, exports, module) { | |
var exec = require("cordova/exec"); | |
var TelephoneNumber = function () {}; | |
var TelephoneNumberError = function(code, message) { | |
this.code = code || null; | |
this.message = message || ''; | |
}; | |
TelephoneNumber.NO_TELEPHONE_NUMBER = 0; | |
TelephoneNumber.prototype.get = function(success,fail) { | |
var errorCallback = typeof fail !== 'function' ? null : function(code) { | |
fail({"code": code}); | |
}; | |
exec(success,errorCallback,"TelephoneNumber", "get",[]); | |
}; | |
var telephoneNumber = new TelephoneNumber(); | |
module.exports = telephoneNumber; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var telephoneNumber = cordova.require("cordova/plugin/telephonenumber"); | |
telephoneNumber.get(function(result) { | |
console.log("result = " + result); | |
}, function(error) { | |
console.log("error = " + error.code); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, what do we do with the java file please?