How do I get my custom account type to show up in the android contacts app?

折月煮酒 提交于 2019-12-30 04:42:07

问题


I've created a custom account type and I can successfully create contacts of that type in the android ContactsContract ContentProvider. But I'm having a lot of trouble figuring out how to get my custom account label and icon to show up when editing the contact in the default contacts app.

When editing a custom contact type, the label should be something like " contact", with your app's icon to the right. Instead, editing contacts of my type always show a label of "Phone-only, unsynced contact". See the first screenshot below for an example.

The weird thing is that it does pick up my account name, which you can see in the screenshot underneath the incorrect label (it starts with "+1415").

And I have successfully shown my app's label and icon in the settings app under accounts, so I know I'm doing something right. See the second screenshot below for proof of that (the account label is "Bolt").

I have the following authenticator.xml:

<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
    android:accountType="@string/account_type"
    android:label="@string/app_name"
    android:icon="@drawable/app_icon"
    android:smallIcon="@drawable/app_icon" />

And this is my syncadapter.xml:

<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
    android:contentAuthority="@string/contacts_content_authority"
    android:accountType="@string/account_type"
    android:userVisible="true"
    android:allowParallelSyncs="false"
    android:isAlwaysSyncable="true"
    android:supportsUploading="false" />

Can anyone point me to where I'm going wrong with this? I can provide more info as necessary. I've tried creating the contact from within my SyncAdapter using the CLIENT_IS_SYNCADAPTER parameter but that didn't change anything. I've tried a few other things as well but nothing's worked yet.


回答1:


I finally figured out what the issue was.

In my sync-adapter element the android:contentAuthority attribute was set to a custom content authority for my own contacts ContentProvider, which is technically what I use to query and write contact data. But it turns out to get your contacts to show up in the default contacts app this attribute must be set to "com.android.contacts".



来源:https://stackoverflow.com/questions/21011569/how-do-i-get-my-custom-account-type-to-show-up-in-the-android-contacts-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!