Contact Custom Fields

后端 未结 3 438
我寻月下人不归
我寻月下人不归 2020-12-10 07:55

Alright, I\'m a little new to the Android SDK, so forgive me if my question doesn\'t make sense or is very trivial. I\'d like to add a custom field for contacts, that contai

3条回答
  •  甜味超标
    2020-12-10 08:56

    To add custom field you need to add custom mimetype in MIMETYPE table. But we dont have direct access to MIMETYPE table. so following can be done:

    public static final String MIMETYPE="vnd.android.cursor.item/favsong";
    
             ContentValues values = new ContentValues();
        values.put(Data.RAW_CONTACT_ID, id);
        values.put(Data.MIMETYPE, MIMETYPE);
        values.put(Data.DATA1, "MyFavSong");
        Uri dataUri = getContentResolver().insert(Data.CONTENT_URI, values);
    

    what we have done is , we have created a custom MIMETYPE as string constant. Then using insert query we are inserting a new row in Data table having RAW_CONTACT_ID of a person we want to associate our custom field , in MIMETYPE column we put our own mimetype and in DATA1 column we put favourite song . here system internally add the new mimetype in MIMETYPE table and give it an ID and that ID is used in mimetype_id column of Data table.

提交回复
热议问题