我需要使用PhoneGap的從Android設備獲取聯繫人列表.....我按照這個一個PhoneGap的聯繫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'); 它背後的原因是什麼?是版本問題?任何嚮導讚賞 謝謝
你最好檢查了'contactError','警報(「onError的!」)'是沒有意義的。並且引發了任何錯誤/異常?看看你的LogCat outupt。 – xiaowl 2012-07-30 11:34:46