2012-07-30 51 views
0

我需要使用PhoneGap的從Android設備獲取聯繫人列表.....我按照這個一個PhoneGap的聯繫API問題

PHONEGAP CONTACT API

,並寫了這個代碼

<!DOCTYPE html> 

PhoneGap設備就緒示例

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

// Call onDeviceReady when PhoneGap is loaded. 
// 
// At this point, the document has loaded but phonegap-1.0.0.js has not. 
// When PhoneGap is loaded and talking with the native device, 
// it will call the event 'deviceready'. 
// 
document.addEventListener("deviceready", onDeviceReady, false); 

// PhoneGap is loaded and it is now safe to make calls PhoneGap methods 
// 
function onDeviceReady() { 
    var options = new ContactFindOptions(); 
    options.filter="Bob"; 
    var fields = ["displayName", "name"]; 
    navigator.contacts.find(fields, onSuccess, onError, options); 
} 
function onSuccess(contacts) { 
    alert('OnSucess!'); 
    for (var i=0; i<contacts.length; i++) { 
     console.log("Display Name = " + contacts[i].displayName); 
    } 
} 

// onError: Failed to get the contacts 
// 
function onError(contactError) { 
    alert('onError!'); 
} 

</script> 

我已經給這個權限在我的清單

  • android.permission.GET_ACCOUNTS
  • android.permission.READ_CONTACTS
  • android.permission.WRITE_CONTACTS

&這個插件

<plugin name="Contacts" value="com.phonegap.ContactManager"/> 

我使用PhoneGap的版本1.4.1,當我始終運行我的應用程序得到警報( '的OnError'); 它背後的原因是什麼?是版本問題?任何嚮導讚賞 謝謝

+1

你最好檢查了'contactError','警報(「onError的!」)'是沒有意義的。並且引發了任何錯誤/異常?看看你的LogCat outupt。 – xiaowl 2012-07-30 11:34:46

回答

2

你使用哪個ADT版本?
如果您使用ADT 20,那麼您必須在libs文件夾中手動添加phonegap jar然後才能正常工作。
請嘗試並告訴我。
你也可以參考我的問題,我問,有點類似於你..

Phonegap application stops unexpectedly on Indigo running Android ADT 20

+0

嗨! thnaks的回答....但我已經有libs文件夾中,我已經把phonegap.jar文件.. – Aamirkhan 2012-07-31 04:51:01

+0

請把你的日誌... – 2012-07-31 06:52:44

+0

我沒有得到任何錯誤或任何日誌 – Aamirkhan 2012-07-31 06:58:52