你只需在插入联系人时,在
ContactsContract.Data
表中添加附加行即可。请参阅
documentation中的“contacts.xml结构”部分:
The <ContactsDataKind>
element controls the display of your
application's custom data rows in the contacts application's UI. It
has the following syntax:
<ContactsDataKind
android:mimeType="MIMEtype"
android:icon="icon_resources"
android:summaryColumn="column_name"
android:detailColumn="column_name">
对于每一个联系人,联系人应用
ContactDetailFragment都会添加一个
DataViewEntry
。列表条目充当了构建联系人详细信息界面所需的适配器数据。当点击包含意图的条目时,将调用
startActivity()
。该意图是由数据项的MIME类型和Uri构建而成的。
entry.intent = new Intent(Intent.ACTION_VIEW);
entry.intent.setDataAndType(entry.uri, entry.mimetype);
例如,G+应用程序有以下
es_contacts.xml
文件:
<ContactsDataKind android:summaryColumn="data2" android:detailColumn="data3"
并创建如下行:
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference("raw_contact_id", i1)
.withValue("mimetype", "vnd.android.cursor.item/vnd.googleplus.profile.comm")
.withValue("data4", Integer.valueOf(14))
.withValue("data5", "hangout")
.withValue("data3", context.getString(R.string.start_hangout_action_label));
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference("raw_contact_id", i1)
.withValue("mimetype", "vnd.android.cursor.item/vnd.googleplus.profile")
.withValue("data4", Integer.valueOf(20))
.withValue("data5", "addtocircle")
.withValue("data3", context.getString(R.string.add_to_circle_action_label));