android - How to remove a specific contact from contact list -
i trying delete specific contact not deleting.
here code:
public static boolean deletecontact(context ctx, string phone) { uri contacturi = uri.withappendedpath(contactscontract.phonelookup.content_filter_uri, uri.encode(phone)); cursor cur = ctx.getcontentresolver().query(contacturi, null, null, null, null); try { if (cur.movetofirst()) { { string lookupkey = cur.getstring(cur.getcolumnindex(contactscontract.contacts.lookup_key)); uri uri = uri.withappendedpath(contactscontract.contacts.content_lookup_uri, lookupkey); ctx.getcontentresolver().delete(uri, null, null); } while (cur.movetonext()); } } catch (exception e) { system.out.println(e.getstacktrace()); } return true; }
try use code.
contentresolver cr = getcontentresolver(); cursor cur = cr.query(contactscontract.contacts.content_uri, null, null, null, null); while (cur.movetonext()) { try{ string lookupkey = cur.getstring(cur.getcolumnindex( contactscontract.contacts.lookup_key)); uri uri = uri.withappendedpath(contactscontract. contacts.content_lookup_uri, lookupkey); system.out.println("the uri " + uri.tostring()); cr.delete(uri, null, null); } catch(exception e) { system.out.println(e.getstacktrace()); } }
to delete specific contact modify query according needs.
cr.delete(uri, null, null);
Comments
Post a Comment