Get contacts from android device filter by account type -
i writen application contact sync. sync contact server device. when sync done user haduy@lvsolution.vn, want contact's haduy user. contact in device, don't filter haduy user. want contact of haduy@lvsolution account.
public void getcontact() { string phone = null; string name = null; listcontact.clear(); contentresolver cr = getcontentresolver(); cursor cur = cr.query(contactscontract.contacts.content_uri, null, null, null, null); if (cur.getcount() > 0) { while (cur.movetonext()) { string id = cur.getstring(cur.getcolumnindex(contactscontract.contacts._id)); name = cur.getstring(cur.getcolumnindex(contactscontract.contacts.display_name)); if (integer.parseint(cur.getstring(cur.getcolumnindex(contactscontract.contacts.has_phone_number))) > 0) { system.out.println("name : " + name + ", id : " + id); // phone number cursor pcur = cr.query(contactscontract.commondatakinds.phone.content_uri, null, contactscontract.commondatakinds.phone.contact_id + " = ?", new string[]{id}, null); while (pcur.movetonext()) { phone = pcur.getstring( pcur.getcolumnindex(contactscontract.commondatakinds.phone.number)); system.out.println("phone" + phone); } contact contact = new contact(name,phone); listcontact.add(contact); pcur.close(); } } } }
you can contacts account_type rawcontatcs follows.
string youraccounttype="";//ex: "com.whatsapp" cursor c = getcontentresolver().query( rawcontacts.content_uri, new string[] { rawcontacts.contact_id, rawcontacts.display_name_primary }, rawcontacts.account_type + "= ?", new string[] { youraccounttype }, null); arraylist<string> contactlist = new arraylist<string>(); int contactnamecolumn = c.getcolumnindex(rawcontacts.display_name_primary); while (c.movetonext()) { // can read rawcontacts.contact_id read // contactscontract.contacts table or of other related ones. contactlist.add(c.getstring(contactnamecolumn)); } c.close();
Comments
Post a Comment