Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I set up my custom mime type, a syncadapter, and a contacts.xml file that has a ContactsDataKind element.

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. Here's a screenshot of the G+ integration in People: http://i.imgur.com/QotHjDk.png

Thank you for your time!

like image 824
Quint Stoffers Avatar asked Jul 04 '14 08:07

Quint Stoffers


1 Answers

You just need to add additional rows in the ContactsContract.Data table when inserting a contact. See "contacts.xml structure" in the documentation:

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">

For each one of these, the Contact's app ContactDetailFragment adds one DataViewEntry. The list entries acts as the data for an adapter used to build the contact details UI. When an entry containing an Intent is clicked, startActivity() is called. This Intent is built from the data item's MIME type and 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:

<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));
like image 119
matiash Avatar answered Oct 19 '22 03:10

matiash