3

I want to send sms through phonegap application , i search internet and found this link but in that i can able to make call Phonegap Webview - Show contacts list for Android Only

is there any good toutorial about getting contactlist of devices and sending sms through phonegap ?

I tried this code but it return me on only one contact named "Pascal Loius" which dont even exists in my contact list

<!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>

Thanks

4

1 回答 1

0

Change your onDeviceReady method by below and check if you get contacts or not.

function onDeviceReady() {
      var options = new ContactFindOptions();
      options.filter="";
      options.multiple=true; 
      var fields = ["*"];
      navigator.contacts.find(fields, onSuccess, onError, options);
}
于 2016-07-02T09:55:03.683 回答