The data structure for contacts is based on three separate tables: Contacts, RawContacts and Data. A Contact can have multiple RawContacts, which can have multiple Data rows. Each data row has a mime type that specifies what kind of data is stored in that row. Contact name is stored in a row with the mime type StructuredName.CONTENT_TYPE.
So, in order to change the contact name you first need to find the Data row that contains the name and then update that Data row. The provider will take care of the rest (e.g. promoting the name to the level of RawContact and then Contact). I hope this helps, - Dmitri On Fri, May 7, 2010 at 2:46 AM, JKDESAI <[email protected]> wrote: > > Thanks for your replay. > > Here is the scenario I am following. > > First of all, I am getting a curser for the Contact at some particular > Id using this: > > contactCursor = > getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, > null, > ContactsContract.Contacts._ID + " = ?", > new String[]{id}, null); > > Now I need to update the GIVEN_NAME and FAMILY_NAME of this contact. > > For that, What Id I have to pass in the withSelection(String, > String[]) method along with Data.CONTACT_ID ? > > I have tried by getting RAW_DATA_ID but no success. > > Please help me. > > On May 5, 9:53 pm, Dmitri Plotnikov <[email protected]> wrote: > > Your query says: "update _all_ data rows for this contact, setting one of > > the fields to "John" and another to "Abraham". Data rows include phone > > numbers, emails, photos, you-name-it. What you need to do is find a > > specific data row you want to update and then use its _id in the > selection > > (or, more commonly, in the URI itself). > > > > Cheers, > > - Dmitri > > > > > > > > On Tue, May 4, 2010 at 6:46 AM, JKDESAI <[email protected]> wrote: > > > > > On Apr 19, 2:41 pm, Timo Prill <[email protected]> wrote: > > > > hi all, > > > > > > i got a problemupdatingacontact'sdetails. > > > > i use the following code to update thecontactname: > > > > "operations" is a ArrayList of ContentProviderOperation. > > > > > > operations.add(ContentProviderOperation.newUpdate( > > > > ContactsContract.Data.CONTENT_URI) > > > > .withSelection(Data._ID + "=?", new > String[]{id}) > > > > > > .withValue(Data.MIMETYPE,StructuredName.CONTENT_ITEM_TYPE) > > > > .withValue(StructuredName.GIVEN_NAME, firstName) > > > > .withValue(StructuredName.FAMILY_NAME, lastName) > > > > .build()); > > > > > > contentResolver.applyBatch(ContactsContract.AUTHORITY, operations); > > > > > > but after this query, thecontactname is not updated.. (at least the > > > > name did not change in the phone's addressbook) > > > > i cant figure out why...what am i doing wrong? must be a simple thing > i > > > > am missing.. > > > > > > thanks in advance > > > > timo > > > > > > -- > > > > You received this message because you are subscribed to the Google > > > > Groups "Android Developers" group. > > > > To post to this group, send email to > [email protected] > > > > To unsubscribe from this group, send email to > > > > [email protected]<android-developers%[email protected]> > <android-developers%[email protected]<android-developers%[email protected]> > > > > > > For more options, visit this group athttp:// > > > groups.google.com/group/android-developers?hl=en > > > > > Hi, > > > > > I have used your code snippet for updating contact details with API > > > 2.0. > > > > > But using that, display name is updated successfully, but it deletes > > > all the other information like phone number and email. > > > > > Can you tell me why it happens?..or I am missing something... > > > > > Here Data used is "android.provider.ContactsContract.Data". > > > > > The same code I have used is as below: > > > > > ArrayList<ContentProviderOperation> > > > operations = > > > new > > > ArrayList<ContentProviderOperation>(); > > > > > operations.add(ContentProviderOperation.newUpdate( > > > > > ContactsContract.Data.CONTENT_URI).withSelection( > > > Data.CONTACT_ID + "=?", new String[] > > > { id }).withValue( > > > StructuredName.GIVEN_NAME, > "John").withValue( > > > StructuredName.FAMILY_NAME, > > > "Abraham").build()); > > > > > try { > > > > > getContentResolver().applyBatch(ContactsContract.AUTHORITY, > > > operations); > > > } catch (RemoteException e) { > > > System.out.println("Exception : > " + > > > e.getMessage()); > > > e.printStackTrace(); > > > } catch (OperationApplicationException > e) { > > > System.out.println("Exception : > " + > > > e.getMessage()); > > > e.printStackTrace(); > > > } > > > > > Please share your thoughts. > > > > > -- > > > You received this message because you are subscribed to the Google > > > Groups "Android Developers" group. > > > To post to this group, send email to > [email protected] > > > To unsubscribe from this group, send email to > > > [email protected]<android-developers%[email protected]> > <android-developers%[email protected]<android-developers%[email protected]> > > > > > For more options, visit this group at > > >http://groups.google.com/group/android-developers?hl=en > > > > -- > > You received this message because you are subscribed to the Google > > Groups "Android Developers" group. > > To post to this group, send email to [email protected] > > To unsubscribe from this group, send email to > > [email protected]<android-developers%[email protected]> > > For more options, visit this group athttp:// > groups.google.com/group/android-developers?hl=en > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected]<android-developers%[email protected]> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

