以下脚本应该返回联系人列表以及他们的电子邮件、电话号码和头像(照片)。
它就像一个魅力,当我删除头像(照片)检索代码时,我将它添加回来。脚本中断。有没有人有任何尝试通过 phonegap 显示联系人照片的经验?
<!DOCTYPE html>
<html>
<head>
<title>Contact Example</title>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript" charset="utf-8" src="cordova-1.9.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() {
// specify contact search criteria
var options = new ContactFindOptions();
options.filter=""; // empty search string returns all contacts
options.multiple=true; // return multiple results
filter = ["displayName", "name", "phoneNumbers"];
// find contacts
navigator.contacts.find(filter, onSuccess, onError, options);
}
// onSuccess: Get a snapshot of the current contacts
//
function onSuccess(contacts) {
console.log(contacts.length);
for (var i=0; i<contacts.length; i++) {
var LI=$("#list").append('<li>'+contacts[i].displayName+'</li>');
if (contacts[i].phoneNumbers) {
for (var j=0; j<contacts[i].phoneNumbers.length; j++) {
$(LI).append('<span>'+contacts[i].phoneNumbers[j].value+'</span><Br/>');
}
}
if (contacts[i].emails) {
for (var j=0; j<contacts[i].emails.length; j++) {
$(LI).append('<span>'+contacts[i].emails[j].value+'</span><br/>');
}
}
if (contacts[i].photos) {
for (var j=0; j<contacts[i].photos.length; j++) {
alert(contacts[i].photos[j].value);
//$(LI).append('<span>'+contacts[i].photos[j].value+'</span><br/>');
}
}
/*if (contacts[i].photos) {
for (var j=0; j<contacts[i].photos.length; j++) {
$(LI).append('<img src="'+contacts[i].photos[j].value+'"/><br/>');
}
}*/
}
};
// onError: Failed to get the contacts
//
function onError(contactError) {
alert('onError!');
}
</script>
</head>
<body>
<h1>Example</h1>
<p>All Contacts in a list</p>
<ul id="list">
</ul>
</body>