Sunday, June 15, 2014

How to read phonebook with phonegap from android

                function queryPhoneBook()
                {
// find all contacts field
var options = new ContactFindOptions();
options.filter="";
options.multiple=true;
var fields = ["name", "phoneNumbers"];
navigator.contacts.find(fields, onSuccess, onError, options);
                }

                function onSuccess(contacts) {
                //navigator.notification.alert(contacts.length);
                var j = 0;
                $.mobile.showPageLoadingMsg(true);
                //$("#userList").html('');
                for(var i=0; i < contacts.length ; i++)
                {
if( contacts[i].phoneNumbers == null )
continue;
                if(contacts[i].phoneNumbers.length > 0)
                {
                //navigator.notification.alert(contacts[i]);
                //var temp = contacts[i].displayName + "" + contacts[i].phoneNumbers[0].value;
        //navigator.notification.alert(temp);

var htmlData = '<li id="'+j+'"><a href="#"><h2>'+contacts[i].displayName+'</h2><p class="ui-li-aside">'+contacts[i].phoneNumbers[0].value+'</p></a></li>';
$("#userList").append(htmlData).listview('refresh');
j++;
        }
        }
        $.mobile.changePage($("#index"), { transition : "slide"});
$.mobile.hidePageLoadingMsg();
}

No comments:

Post a Comment