android - Accessing the contact Content Provider -


i tring access contact content provider. wrote following code

cursor cur= getcontentresolver().query(contactscontract.contacts.content_uri, null,null,null,null);      startmanagingcursor(cur);      string[] result=new string[cur.getcount()];      if(cur.movetofirst())     {         int nameidx=cur.getcolumnindexorthrow(contactscontract.contacts.display_name);         int ididx=cur.getcolumnindexorthrow(contactscontract.contacts._id);         string strname=cur.getstring(nameidx);         string strid=cur.getstring(ididx);          result[cur.getposition()]=strname+"("+strid+")";     }while(cur.movetonext());     stopmanagingcursor(cur); } 

but showing 1 contact name want show contact available please tell me how that.

try instead

cursor cur= getcontentresolver().query(contactscontract.contacts.content_uri, null,null,null,null);  startmanagingcursor(cur);  string[] result=new string[cur.getcount()];  (boolean hasdata = cursor.movetofirst(); hasdata; hasdata = cursor.movetonext()) {     int nameidx=cur.getcolumnindexorthrow(contactscontract.contacts.display_name);     int ididx=cur.getcolumnindexorthrow(contactscontract.contacts._id);     string strname=cur.getstring(nameidx);     string strid=cur.getstring(ididx);      result[cur.getposition()]=strname+"("+strid+")"; } stopmanagingcursor(cur); } 

Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -