Android : How to update display name with email id?

on Friday, October 10, 2014


I am trying to update a contact display name & email.After lot of efforts achieve that from following code snipet.But there is a issue any name I supply for update it appended 2 after it when I see it in contact app. ArrayList ops = new ArrayList();



ops.add(ContentProviderOperation
.newUpdate(
ContactsContract.Data.CONTENT_URI)

.withSelection(
ContactsContract.CommonDataKinds.Email.CONTACT_ID
+ " = ?",
new String[] { String.valueOf(model
.getContactid()) })
.withValue(ContactsContract.Data.MIMETYPE,
Email.CONTENT_ITEM_TYPE)
.withValue(
ContactsContract.CommonDataKinds.Email.DATA,
"priyankay27@gmail.com")
.withValue(
ContactsContract.CommonDataKinds.Email.DISPLAY_NAME,
"priyanka")
.withValue(
ContactsContract.CommonDataKinds.Email.TYPE,
ContactsContract.CommonDataKinds.Email.TYPE_WORK)
.build());

getContentResolver().applyBatch(
ContactsContract.AUTHORITY, ops);

Context ctx = getApplicationContext();
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(ctx,
"Update successful", duration);
toast.show();

Logger.debug("Update successful");


This updates display name as "priyanka 2" instead of "priyanka" as you seen 2 get appended after display name.


0 comments:

Post a Comment