|
phonegap contacts 访问设备通讯录api
Contacts.create是用于创建并返回一个新Contact对象的同步函数。
该方法不会将新创建的Contact对象持久化到设备的通讯录数据库。可通过调用Contact.save方法将新建的Contact对象持久化到设备。
向设备中创建一个通讯录名称:- <!DOCTYPE HTML>
- <html>
- <head>
- <meta charset="utf-8">
- <title>PhoneGap-Contact</title>
- <link rel="stylesheet" href="../jquery.mobile-1.1.1/jquery.mobile-1.1.1.css" />
- <script src="../jquery.mobile-1.1.1/jquery.js"></script>
- <script src="../jquery.mobile-1.1.1/jquery.mobile-1.1.1.js"></script>
- <script type="text/javascript" charset="utf-8" src="../cordova-1.9.0.js"></script>
- <script type="text/javascript">
- $(document).ready(function(){
- document.addEventListener("deviceready", myDeviceReadyListener, false);
- });
-
- function myDeviceReadyListener(){
- var contact = navigator.contacts.create({"displayName":"张三1"});
- contact.save(successFunction,ErrorFunction);
- }
-
- successFunction = function(info){
- console.log("添加成功,displayName" + info.displayName);
- }
-
- ErrorFunction = function(code){
- console.log("添加失败,code" + code);
- }
-
-
- </script>
- </head>
- <body>
- <div data-role="page">
- <div data-role="header">
- <h1>PhoneGap实战</h1>
- </div>
- <div data-role="content">
- </div>
- <div data-role="footer">
- <h4> </h4>
- </div>
- </div>
- </body>
- </html>
复制代码 |
|