简体   繁体   English

联系人应用中的自定义操作(类似于G +)

[英]Custom actions in Contacts app (similar to G+)

I'm creating an application that I'd like to integrate with Android's contacts/people application. 我正在创建一个我想与Android的联系人/人员应用程序集成的应用程序。 I set up my custom mime type, a syncadapter, and a contacts.xml file that has a ContactsDataKind element. 我设置了自定义mime类型,一个syncadapter和一个带有ContactsDataKind元素的contacts.xml文件。

This seems to work fine, but it seems it's not possible to define multiple actions per data kind (in this case, I'd like people to be able to view a contact's profile, as well as send them a message directly. 这似乎工作正常,但似乎不可能为每种数据类型定义多个操作(在这种情况下,我希望人们能够查看联系人的配置文件,以及直接向他们发送消息。

The G+ app seems to handle this, but I've been unable to figure out how they did it. G +应用程序似乎处理这个问题,但我一直无法弄清楚他们是如何做到的。 Here's a screenshot of the G+ integration in People: http://i.imgur.com/QotHjDk.png 以下是People中G +集成的屏幕截图: http//i.imgur.com/QotHjDk.png

Thank you for your time! 感谢您的时间!

You just need to add additional rows in the ContactsContract.Data table when inserting a contact. 插入ContactsContract.Data时,只需ContactsContract.Data表中添加其他行 See "contacts.xml structure" in the documentation : 请参阅文档中的“contacts.xml结构”:

The <ContactsDataKind> element controls the display of your application's custom data rows in the contacts application's UI. <ContactsDataKind>元素控制联系人应用程序UI中应用程序的自定义数据行的显示。 It has the following syntax: 它具有以下语法:

 <ContactsDataKind android:mimeType="MIMEtype" android:icon="icon_resources" android:summaryColumn="column_name" android:detailColumn="column_name"> 

For each one of these, the Contact's app ContactDetailFragment adds one DataViewEntry . 对于其中的每一个,Contact的应用程序ContactDetailFragment添加一个DataViewEntry The list entries acts as the data for an adapter used to build the contact details UI. 列表条目充当用于构建联系人详细信息UI的适配器的数据。 When an entry containing an Intent is clicked, startActivity() is called. 单击包含Intent的条目时,将调用startActivity() This Intent is built from the data item's MIME type and Uri. 此Intent是根据数据项的MIME类型和Uri构建的。

entry.intent = new Intent(Intent.ACTION_VIEW);
entry.intent.setDataAndType(entry.uri, entry.mimetype);

For example, the G+ app has the following es_contacts.xml : 例如,G +应用程序具有以下es_contacts.xml

<ContactsDataKind android:summaryColumn="data2" android:detailColumn="data3"

And creates the rows like this: 并创建如下行:

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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM