I am trying to delete a specific contact! I searched a lot, but every code I tried does not work!
public void delete(String name,String numero)
{
Cursor cur = getContentResolver().query(Contacts.CONTENT_URI,null, null, null, null);
while (cur.moveToNext())
{
try
{
String[] selectionArgs=new String[]{String.valueOf(numero)};
String lookupKey = cur.getString(cur.getColumnIndex(Contacts.LOOKUP_KEY));
Uri uri = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey);
getContentResolver().delete(uri, Phone.NUMBER +"=?", selectionArgs);
}
catch(Exception e)
{
System.out.println(e.getStackTrace());
}
}
}
I also tried this instead of specifying selectionArgs, but nothing
getContentResolver().delete(uri, Contacts.DISPLAY_NAME +"="+ name, null);
and tried to change Contacts.to ContactsContract.Contacts., but still tried to delete using Contact displayname instead of number. It seems that the choice is not working! Uri$HierarchicalUriIs uri value right?
What is the problem?
source
share