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

后端 未结 1 1849
礼貌的吻别
礼貌的吻别 2020-12-01 08:31

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.

相关标签:
1条回答
  • 2020-12-01 09:14

    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");
            }
        }
    
    0 讨论(0)
提交回复
热议问题