Search code examples
androidandroid-contactsandroid-6.0-marshmallowandroid-6.0.1-marshmallow

Android contacts - custom field icon not showing in android 6


The goal

I'm working on application that keeps own contacts in contacts database. I want to add my own field with my logo that leads to my application's edit form.

What I did already

Working with this tutorial: http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-2/ and a couple of other sources i have assembled something like this:

AndroidMainifest.xml:

    <service android:enabled="true" android:exported="true" android:name="com.MySyncAdapterService" android:process=":contacts">
       <intent-filter android:icon="@drawable/icon">
          <action android:name="android.content.SyncAdapter" />
       </intent-filter>
       <meta-data android:name="android.provider.CONTACTS_STRUCTURE" android:resource="@xml/contacts" />
       <meta-data android:name="android.content.SyncAdapter" android:resource="@xml/sync_contacts" />
    </service>

Contacts.xml:

<ContactsAccountType xmlns:android="http://schemas.android.com/apk/res/android">
  <ContactsDataKind
    android:icon="@drawable/icon"
    android:smallIcon="@drawable/icon"
    android:mimeType="vnd.android.cursor.item/vnd.my.contact"
    android:summaryColumn="data2"
    android:detailColumn="data3"
    android:detailSocialSummary="true" >
  </ContactsDataKind>
</ContactsAccountType>

The problem

As can be seen on first image my custom field is displayed with icon properly in Android 4.3. Unfortunatetly Android 6.0.1 does display my field but without the icon.

4.3 version 6.0.1 version

Any help will be appreciated, I'm running out of hair on my head ;)


Solution

  • I think i resolved my problem. Android 6.0 seems to ignore ContactsDataKind icon property. In order to provide icon for custom field you need to provide action hadndling it. It will use intent filter's icon if it's provided. If not it will use your application's icon.

    <activity android:name=".ContactActivity">
      <intent-filter android:icon="@drawable/icon">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="vnd.android.cursor.item/vnd.my.contact" />
      </intent-filter>
    </activity>