Update a contact

peacemaker

Expert
Licensed User
Longtime User
Any solution ?
But without creation of a new contact and deleting all old existing, to avoid losing all other phones, emails.... of the existing contact.
 
Last edited:

vb1992

Well-Known Member
Licensed User
Longtime User
I am thinking that the only way possible now,
is if you get an intent working like this below
And this would only work on Android 2.0 and above
Maybe someone on here can get this intent working...

B4X:
Uri uri = ContentUris.withAppendedId(Contacts.Phones.CONTENT_URI, Integer.parseInt(pID));
 ContentValues values = new ContentValues();
 values.put(People.Phones.TYPE, People.Phones.TYPE_MOBILE);
 values.put(People.Phones.NUMBER, "4084444444");
 values.put(ContactsContract.Data.RAW_CONTACT_ID,recNo);
 //getContentResolver().update(uri, values, Null, Null);
 Int rows = getContentResolver().update(uri, values, Null, Null);




B4X:
Uri phoneUri = null;
Uri emailUri = null;

// Add a phone number for Abraham Lincoln.  Begin with the URI for
// the new record just returned by insert(); it ends with the _ID
// of the new record, so we don't have to add the ID ourselves.
// Then append the designation for the phone table to this URI,
// and use the resulting URI to insert the phone number.
phoneUri = Uri.withAppendedPath(uri, People.Phones.CONTENT_DIRECTORY);

values.clear();
values.put(People.Phones.TYPE, People.Phones.TYPE_MOBILE);
values.put(People.Phones.NUMBER, "1233214567");
getContentResolver().insert(phoneUri, values);

// Now add an email address in the same way.
emailUri = Uri.withAppendedPath(uri, People.ContactMethods.CONTENT_DIRECTORY);

values.clear();
// ContactMethods.KIND is used to distinguish different kinds of
// contact methods, such as email, IM, etc. 
values.put(People.ContactMethods.KIND, Contacts.KIND_EMAIL);
values.put(People.ContactMethods.DATA, "[email protected]");
values.put(People.ContactMethods.TYPE, People.ContactMethods.TYPE_HOME);
getContentResolver().insert(emailUri, values);
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Thanks, vb1992.
Actually, it'd better to have an UpdateContact function without an intent calling.
But any would be OK - the main is not to delete the existing contact fields, updating the Note (or other).
Now i use CreateContactEntry2 of miscUtil lib and DeleteContactById of fgContacts lib - it's complex to arrange, but works :) - but a contact always is being re-created, no possibility to use contacts with several fields filled.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Still no solution to update an existing contact ?
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Up ? :)
Actually, it needs to add just one more NOTES field into the existing contact, without losing existing numbers\emails...
is a small lib for some money from me possible, Java-masters ?
 
Last edited:
Upvote 0
Top