android - Cant get contacts given name and family name on ICS -
i have code getting contacts first name , family name:
uri = contactscontract.data.content_uri; cursor curname = getcontentresolver().query(uri, null, contactscontract.data.contact_id +" = "+ contactid, null, null); if (curname.getcount() > 0){ curname.movetofirst(); string namegiven = curname.getstring(curname.getcolumnindex(contactscontract.commondatakinds.structuredname.given_name)); string namefamily = curname.getstring(curname.getcolumnindex(contactscontract.commondatakinds.structuredname.family_name)); log += namegiven + ", " + namefamily + ": "; }
i have 1 contact dont need loop. on 2.3.5 device works ok, returning right names. on 4.0.4 device returns null both fields, if requesting display name provides correctly.
what problem?
well, _id in info table , contacts table 2 different things. should utilize raw_contacts_id instead of _id when querying info table.
let me throw in quick piece of code started
// projection string[] projection = new string[] {contactscontract.commondatakinds.structuredname.family_name, contactscontract.commondatakinds.structuredname.given_name, contactscontract.commondatakinds.structuredname.middle_name}; string = contactscontract.data.raw_contact_id + " = ? , " + contactscontract.data.mimetype + " = ?"; string[] whereparameters = new string[]{this.contact_id, contactscontract.commondatakinds.structuredname.content_item_type}; //request cursor contacts = this.resolver.query(contactscontract.data.content_uri, projection, where, whereparameters, null); //iteration if (contacts.movetofirst()) { //code here, e.g string namegiven = contacts.getstring(contacts.getcolumnindex(contactscontract.commondatakinds.structuredname.given_name)); string namefamily = contacts.getstring(contacts.getcolumnindex(contactscontract.commondatakinds.structuredname.family_name)); //log += namegiven + ", " + namefamily + ": "; } contacts.close();
android android-contacts
No comments:
Post a Comment