2

I know how to add/edit email address in a contact programmatically, but i don't know how to retrieve/modify SIP_address/Internet_call in a contact,I've read many documentation based on it, including Modifying contact information. Please help me to implement this

Community
  • 1
  • 1
Harsh Vardhan
  • 675
  • 1
  • 11
  • 24

1 Answers1

1

Changing the Sip Address is exactly the same as changing a contact's e-mail address. Just use ContactsContract.CommonDataKinds.SipAddress instead ofContactsContract.CommonDataKinds.Email.

A small pre-coffee example:

import java.util.ArrayList;
import android.content.ContentProviderOperation;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.CommonDataKinds.SipAddress;
//[...]
private String mSipAddress = "cecin\'estpasunesipaddress";
//[...]
    try {
        ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

        ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
           .withSelection(Data.RAW_CONTACT_ID + " = ?", new String[] {mRawContactId})
           .withSelection(Data._ID + " = ?", new String[] {mDataId})
           .withValue(Data.MIMETYPE, SipAddress.CONTENT_ITEM_TYPE)
           .withValue(Data.DATA1, mSipAddress)
           .withValue(SipAddress.TYPE, SipAddress.TYPE_HOME)
           .build());
        getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
}
//[...]

See this GitHub repository for an example on how to get the fields that are not declared here. I got it from this answer. Relevant documentation.

Community
  • 1
  • 1
  • Hey sorry for getting back late.. I have added your code to the inserting (few lines edited) and updating part of the code and this is what is get when I debugged it And received "Contacts have stopped" alert when I check the updated contact. It goes to "insert sip address" block of code even if the contact has a sip address already. I believe the selectioArgs is not correct for updating the SIP Address in the given project. – Harsh Vardhan Dec 05 '13 at 15:20
  • Ah, I now see you checked out that answer I referred to before, nice. I can't test the code now because I'm on an OS without the android sdk, but it should work. Did you say you can change some other data like the email address with the same code? – Sietse van der Molen Dec 05 '13 at 17:07
  • Yes..I simply replaced the Email.something to SIpAddress.something. – Harsh Vardhan Dec 06 '13 at 20:30