tags:

views:

56

answers:

2

Hi! I am trying to update contact email address using this code

String selectEmail = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='"  + 
    ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE + "'";
    String[] emailArgs = new String[]{Id}; 
    ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
    .withSelection(selectEmail, emailArgs)
    .withValue(ContactsContract.CommonDataKinds.Email.DATA, email)
    .build()); 

I am getting "Id" using this code

String[] returnVals = new String[] {ContactsContract.CommonDataKinds.Phone.CONTACT_ID};
   this.cur = this.cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
               returnVals, 
               ContactsContract.CommonDataKinds.Phone.NUMBER + " = \"" + phoneNumber + "\"", 
               null, 
               null);

My questions are

1) Am I using correct way for getting Contact_ID using Phone number? 2) Contacts are not updating correctly, it is changing all fields like email, name and number.Am I doing some thing wrong?

Need help

+1  A: 

Please format your code, before reading this answer... ;)

You can find an example how to update contacts here and an example to do a number lookup here.

Good luck
Tom

TomTasche
thanks for your reply, i have used code given in your mention link but there is no luck, i have formated my code please check does i miss some thing?
ARDaniyal
A: 

Hi, I too am having a similar issue did you resolve the issue? The examples in your links although helpful dont provide the answer, or similar example.

ETT
I am still finding solution. If you find then please let me know. if i found then i will post it
ARDaniyal