I'm trying to edit contact details programmatically. I want to change the contact name having the phone number is equal to 123. Here is my Non working code.
Uri lookupUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode("123"));
// This query will return NAME and ID of contact, associated with phone //number.
Cursor mcursor = getContentResolver().query(lookupUri, new String[]{ContactsContract.PhoneLookup.DISPLAY_NAME, ContactsContract.PhoneLookup._ID}, null, null, null);
//Now retrive _ID from query result
long idPhone = 0;
try {
if (mcursor != null) {
if (mcursor.moveToFirst()) {
idPhone = Long.valueOf(mcursor.getString(mcursor.getColumnIndex(ContactsContract.PhoneLookup._ID)));
String getID = String.valueOf(idPhone);
Toast.makeText(this.getApplicationContext(), getID, Toast.LENGTH_LONG).show();
Uri uri= ContentUris.withAppendedId(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,3625);
ContentValues values = new ContentValues();
values.put(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,"After Changed name");
getContentResolver().update(uri, values, ContactsContract.CommonDataKinds.Phone._ID+"=?", new String[] {String.valueOf(idPhone)});
}
}
} finally {
mcursor.close();
}
Currently I'm finding the phone number and getting the phone number's ID. With ID I'm trying to update it, seems it's not updating the phone number with ID.