android - Delete a single phone type number from a contact -
when 1 of contact have multiple numbers, example:
display name: guesswho
type = home
number = homenumber
type = mobile
number = mobilenumber
type = other
number = othernumber ...
in conclusion ... 1 those.
how can remove type number contact ( let's "mobile" )? have update using userid acquired previous query, or how? need delete single type number, other field of contact must remain intact.
i using piece of code obtaining contact :
int indexname = c.getcolumnindex(contactscontract.commondatakinds.phone.display_name); int indexnumber = c .getcolumnindex(contactscontract.commondatakinds.phone.number); int indextype = c.getcolumnindex(contactscontract.commondatakinds.phone.type); int indexid = c.getcolumnindex(contactscontract.commondatakinds.phone._id); string name = c.getstring(indexname); string number = c.getstring(indexnumber); string type = c.getstring(indextype); string typestored = (string) phone.gettypelabel(mcontext.getresources(), integer.parseint(type), ""); log.i("type readed : ", typestored); string id = c.getstring(indexid);
where c cursor of query.
each number same contact has it's own id. should use deleting. need contact id. can using line of code:
contactid = cursor.getint(cursor.getcolumnindex(contactscontract.commondatakinds.phone.contact_id));
then delete number using following code:
cursor cur = contentresolver.query(rawcontacts.content_uri, new string[]{rawcontacts._id}, rawcontacts.contact_id + "=?", new string[] {contactid.tostring()}, null); int rowid=0;; if(cur.movetofirst()){ rowid = cur.getint(cur.getcolumnindex(rawcontacts._id)); } arraylist<contentprovideroperation> ops = new arraylist<contentprovideroperation>(); string selectphone = data.raw_contact_id + " = ? , " + data.mimetype + " = ? , " + phone._id + " = ?"; string[] phoneargs = new string[] { integer.tostring(rowid), phone.content_item_type, id.tostring()}; ops.add(contentprovideroperation.newdelete(data.content_uri) .withselection(selectphone, phoneargs).build()); try { contentresolver.applybatch(contactscontract.authority, ops); } catch (remoteexception e) { e.printstacktrace(); } catch (operationapplicationexception e) { e.printstacktrace(); }
Comments
Post a Comment