I am trying to delete a particular contact from phone. I can delete the full contact. How to delete a particular contact using contact id. I want to delete the full datas in
public void deleteContact(Context context, String localContactId)
{
ContentResolver cr = context.getContentResolver();
String rawWhere = ContactsContract.Contacts._ID + " = ? ";
String[] whereArgs1 = new String[]{localContactId};
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, rawWhere, whereArgs1, null);
if(cur != null && cur.getCount() > 0) {
while (cur.moveToNext()) {
try{
String lookupKey = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
cr.delete(uri, null, null);
}
catch(Exception e)
{
System.out.println(e.getStackTrace());
}
}
}
if(cur != null)
cur.close();
}