电话间隙代码无效

时间:2014-04-18 14:23:16

标签: javascript android jquery html cordova

  

      联系示例

<script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script>
<script type="text/javascript" charset="utf-8">

// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);

// Cordova is ready
//
function onDeviceReady() {
    var myContact = navigator.contacts.create({"displayName": "Test User"});
    myContact.note = "This contact has a note.";
    console.log("The contact, " + myContact.displayName + ", note: " + myContact.note);
}


</script>   </head>   <body>
<h1>Example</h1>
<p>Create Contact</p>   </body> </html>

我编译了这段代码并尝试了我的android联系人没有创建测试用户&#34;

1 个答案:

答案 0 :(得分:0)

创建联系人后添加save()并填充属性...

function onDeviceReady() {
    var myContact = navigator.contacts.create({"displayName": "Test User"});
    myContact.note = "This contact has a note.";
    myContact.save(function() {
        console.log("contact saved");
    },
    function() {
        console.log("could not save contact");
    });
    console.log("The contact, " + myContact.displayName + ", note: " + myContact.note);
}