1. Add plugin
D:\mobile\hello>cordova plugin add https://github.com/macdonst/TelephoneNumberPlugin
2. Copy telephonenumber.js
- Copy telephonenumber.js to www/js directory of my project.
- Copy telephonenumber.js to www/js directory of my project.
3. Prepare page
<html><head>
<link rel="stylesheet" href="css/jquery.mobile-1.4.4.min.css" />
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/jquery.mobile-1.4.4.min.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<!-- import telephonenumber.js -->
<script type="text/javascript" charset="utf-8" src="js/telephonenumber.js"></script>
</head><div data-role="header">
<h1>Get telephone number from device</h1>
</div>
<div data-role="main" class="ui-content">
<a href="#" class="ui-btn" id="showmynumber">Show</a>
</div></div>
</html>
<script>
$( "#showmynumber" ).click(function() {
var telephoneNumber = cordova.require("cordova/plugin/telephonenumber");
telephoneNumber.get(function(result) {
alert("result = " + result);
}, function() {
alert("error");
});
});
</script>
5. Edit config.xml
- Add this line to config.xml of my project.
<plugin name="TelephoneNumber" value="com.simonmacdonald.cordova.plugins.TelephoneNumber"/>
6. Run...
D:\mobile\hello>cordova run android
No comments:
Post a Comment