cursor - How to Delete phone number from contact in android? -
i want delete (e.g. mobile number) android database. passing query follow
public class contactdemo extends activity { /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); string number = "2222"; long id = getid(number); int = getcontentresolver().delete(rawcontacts.content_uri, rawcontacts._id+"=?", new string[]{id.tostring()}); system.out.println("deleted"+i); } public long getid(string number){ uri uri = uri.withappendedpath(phonelookup.content_filter_uri, uri.encode(number)); cursor c = getcontentresolver().query(uri, new string[]{phonelookup._id}, null, null, null); while(c.movetonext()){ return c.getlong(c.getcolumnindex(phonelookup._id)); } return null; } }
but deleting entire contact.
what should use delete phone number (not entire contact)?
you use delete method of contentresolver delete whole contact. update phone number of contact empty value, need use contactscontact api.
http://developer.android.com/reference/android/provider/contactscontract.data.html
by providing contact raw id , phone.content_item_type, can request phone number belonging contact , remove of them.
arraylist<contentprovideroperation> ops = lists.newarraylist(); ops.add(contentprovideroperation.newdelete(data.content_uri) .withselection(data._id + "=? , " + data.mimetype + "=?", new string[]{string.valueof(contactid), phone.content_item_type}) .build()); getcontentresolver().applybatch(contactscontract.authority, ops);
Comments
Post a Comment