Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add new field(s) to the contact?

Tags:

android

I want to add a Custom field to the ContactsContract content provider. I'm trying to build a Voip application and would like to add a SIP address(name@domain) field to it. What MIME type will I need to associate with it? Also I want to add a group address field which will have a list of group addresses in it (name@domain, name@domain,...). Which MIME type will I have to associate with this type of field.

I also want to add custom fields to the Call History like a session ID and SIP address(name@domain) field. How can I customize the call history?

It'll be great if someone can give me an example.

like image 759
Tushar Gupta Avatar asked Apr 28 '10 22:04

Tushar Gupta


1 Answers

You have to creat your own mime type for those.

Here is an example that saves a boolean as my custom mime type to the contacts. It uses the latest SDK 2.1

public void saveFormality() {
        try {
            ContentValues values = new ContentValues();
            values.put(Data.DATA1, this.getFormality() ? "1" : "0");
            int mod = ctx.getContentResolver().update(
                    Data.CONTENT_URI,
                    values,
                    Data.CONTACT_ID + "=" + this.getId() + " AND "
                            + Data.MIMETYPE + "= '"
                            + clsContacts.FORMALITY_MIMETYPE + "'", null);

            if (mod == 0) {
                values.put(Data.CONTACT_ID, this.getId());
                values.put(Data.MIMETYPE, clsContacts.FORMALITY_MIMETYPE);
                ctx.getContentResolver().insert(Data.CONTENT_URI, values);
            }
        } catch (Exception e) {
            Log.v(TAG(), "saveFormality failed");
        }
    }
like image 165
Pentium10 Avatar answered Oct 09 '22 02:10

Pentium10