android - Is that possible to delete the phone contact from my application -
i fetched contacts phone , listed in list view.i able remove local contact in listview database want remove phone contact possible. removing purpose using following code.
if (position == 1) { db.deletecontact(item_position + 1); from.remove(item_position); note.notifydatasetchanged(); }
get selected item name , assign name try following code.
contentresolver cr = getcontentresolver(); string = contactscontract.data.display_name + " = ? "; string[] params = new string[] {name}; arraylist<contentprovideroperation> ops = new arraylist<contentprovideroperation>(); ops.add(contentprovideroperation.newdelete(contactscontract.rawcontacts.content_uri) .withselection(where, params) .build()); try { cr.applybatch(contactscontract.authority, ops); } catch (remoteexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (operationapplicationexception e) { // todo auto-generated catch block e.printstacktrace(); } toast.maketext(getapplicationcontext(), "deleted contact name '" + name +"'", toast.length_short).show(); from.remove(item_position); note.notifydatasetchanged();
Comments
Post a Comment