Add a custom field to a phone number

后端 未结 4 1619
执念已碎
执念已碎 2021-01-01 05:34

Am building an app that requires a custom contact field (\'whitelist\', if you were wondering) for every phone number.

However, I only found a way of saving custom d

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-01 06:04

    All right, I figured it out. Maybe there is a better solution, but this works for me:

        values.put(Data.RAW_CONTACT_ID, contactId);
        values.put(Data.DATA1, phoneId);
        values.put(Data.DATA2, "1");
        values.put(Data.DATA5, phoneNum);
        values.put(Data.MIMETYPE, MIMETYPE_WHITELIST_CONTACT);
    getContentResolver().insert(Data.CONTENT_URI, values);
    

    When I query, I just have to add the phoneId to get the result I need:

    getContentResolver().query(Data.CONTENT_URI, {Data.DATA1, Data.DATA2},
     Data.RAW_CONTACT_ID + " = " + contactId +  " AND "  + 
        Data.DATA1 + " = " + phoneId + " AND "  +
                Data.MIMETYPE + "='" + MIMETYPE_WHITELIST_CONTACT+"'", null, null);
    

提交回复
热议问题