2014-04-18 21 views
0

聯絡的例子電話差距代碼是不能工作

<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通訊錄中沒有創建測試用戶」

+0

so can u please g給我一個保存聯繫人的工作代碼 – Abhilash

+0

見下文。這一切都在phonegap文檔... http://docs.phonegap.com/en/1.4.1/phonegap_contacts_contacts.md.html – Archer

回答

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); 
} 
+0

請給我完整的HTML,我是新的 – Abhilash

+0

我已經改變它是完整的'onDeviceReady'功能:) – Archer

+0

我更新了代碼 – Abhilash