我想通过phonegap应用程序发送短信,我搜索互联网并找到此链接,但我可以拨打电话 Phonegap Webview - Show contacts list for Android Only
有没有关于获取设备联系人列表和通过phonegap发送短信的好消息?
我尝试了这段代码,但它只返回了一个名为“Pascal Loius”的联系人,它甚至不在我的联系人列表中
<!DOCTYPE html>
<html>
<head>
<title>Contact Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.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 options = new ContactFindOptions();
options.filter="";
filter = ["displayName","name"];
navigator.contacts.find(filter, onSuccess, onError, options);
}
// onSuccess: Get a snapshot of the current contacts
//
function onSuccess(contacts) {
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>
</head>
<body>
<h1>Example</h1>
<p>Find Contacts</p>
</body>
</html>
谢谢
答案 0 :(得分:0)
按以下方式更改onDeviceReady方法,检查是否有联系人。
function onDeviceReady() {
var options = new ContactFindOptions();
options.filter="";
options.multiple=true;
var fields = ["*"];
navigator.contacts.find(fields, onSuccess, onError, options);
}