Skip to content

Instantly share code, notes, and snippets.

@sgrebnov
Last active August 29, 2015 14:00
Show Gist options
  • Save sgrebnov/11297098 to your computer and use it in GitHub Desktop.
Save sgrebnov/11297098 to your computer and use it in GitHub Desktop.
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
function onSuccess(contacts) {
alert('Found ' + contacts.length + ' contacts.');
console.log(JSON.stringify(contacts));
var image = document.getElementById('contactAva');
// assume there is a contact with photo, but normally we should check for
// contacts.length and .photos.length
var photo = contacts[0].photos[0];
image.src = photo.type == 'url' ? photo.value : ("data:image/jpeg;base64," + photo.value);
};
function onError(contactError) {
alert('onError!');
};
// find all contacts with 'Bob' in any name field
var options = new ContactFindOptions();
options.filter = "Pronin";
options.multiple = true;
options.desiredFields = [navigator.contacts.fieldType.id,
navigator.contacts.fieldType.displayName,
navigator.contacts.fieldType.photos];
var fields = [navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name];
navigator.contacts.find(onSuccess, onError, fields, options);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment