I have written a SyncAdapter to add my application's contacts list to the Android Contacts Provider. In order to do this, I have created my own AccountAuthenticator, a Service to provide access to the Authenticator, a SyncAdapter, and a Service for the SyncAdapter. I can see my account show up in the Android Accounts list (under the main Settings page), and I can see all the contacts from my application appear in Android's Contacts (or People) app. But when I tap the "Accounts" button in the People app, my application's accounts do not appear. And when I edit any individual account which I have previously synced to the Android Contacts Provider (following the advice here), the contact is marked as "Phone-only, unsynced contact." I know I must be doing something wrong, but I have so far been unable to determine what my error is. How do I tell Android that contact X belongs to account Y? I thought it was sufficient to add the account name and account type to the raw contact at creation time, but this seems to be insufficient. What have I missed?
Asked
Active
Viewed 1,653 times
2
-
Similar question posted here, with an answer which seems to get me closer: http://stackoverflow.com/questions/21011569/how-do-i-get-my-custom-account-type-to-show-up-in-the-android-contacts-app – Patrick Brennan Sep 10 '15 at 19:56
-
1At least part of the answer appears to be that I was using my own ContentProvider's authority (e.g. com.example.myapp.contentprovider), both in my syncadapter.xml and in my calls to the ContentResolver to add the account, set it syncable, etc. Instead, I was supposed to use "com.android.contacts". This lets me see my account in the contacts app, but my synced contacts are still flagged as phone-only unsynced contacts, so clearly I haven't fixed all my blunders yet. – Patrick Brennan Sep 10 '15 at 22:51
1 Answers
3
Having spent the last couple of days dealing with this I have an answer:
I assume you have something like the following in your AndroidManifest.xml under your sync service:
<meta-data android:name="android.provider.CONTACTS_STRUCTURE"
android:resource="@xml/contacts"/>
Then in the contacts.xml file referenced here:
<ContactsAccountType
xmlns:android="http://schemas.android.com/apk/res/android">
<EditSchema>
</EditSchema>
</ContactsAccountType>
If the EditSchema is not correct it will switch to a "Phone Only" contact.
The base for what is acceptable is:
<!-- XML for must-have checks. Base definition, which is valid. -->
<ContactsAccountType
xmlns:android="http://schemas.android.com/apk/res/android"
>
<EditSchema>
<DataKind kind="name"
maxOccurs="1"
supportsDisplayName="true"
supportsPrefix="true"
supportsMiddleName="true"
supportsSuffix="true"
supportsPhoneticFamilyName="true"
supportsPhoneticMiddleName="true"
supportsPhoneticGivenName="true"
>
</DataKind>
<DataKind kind="photo" maxOccurs="1" />
</EditSchema>
</ContactsAccountType>
And I eventually found a lot of examples - https://android.googlesource.com/platform/packages/apps/Contacts/+/android-sdk-support_r11/tests/res/xml

davidhodges86
- 301
- 2
- 5
-
Hi i am trying to use the edit schema like maxOccurs for email should be 3 etc. but my device doesn't seems to honour it – alphaguy Jun 13 '19 at 08:39