Search code examples
androidcontactscontractaccountmanager

AccountManager. Account type for contacts


Ok, so I have "fully" functional Account application. Except 1 thing.

My application takes data from SQlite DB and create accounts through ContactContract with Account name and type specified like

contactsOperations.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
                    .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, static_variables.ACCOUNT_TYPE)
                    .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, static_variables.ACCOUNT_NAME)
                    .withYieldAllowed(true)
                    .build());

And on some phones, almost all(and emulators) in standard contacts application I see that account created and Account place is set to static_variables.ACCOUNT_NAME as intended.

But on some devices place is "Unknown"(thought Account is created and exists) and on some contact doesn't visible at all, but exist.

When(on any phone) I check it with

Cursor cursor_raw = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null, null);

I see those contacts in the end with Account name and type setted correctly.

1. That's a first question, what's wrong?

Second more not question, but one more evidence for previous. When I go to System->Accounts-> Add account, I see there my Account type and I can create It.

But when I in standartd contacts application and I press add contact, I see "Google", "Exchange", "SIM" and couple more but not mine. Also in standartd app, when I choosing "Open account settings" (where autosync located) I see same accounts "Google", "Exchange", "SIM" and couple more but not mine.

So second
2. What Account/ContentProvider/or something else is wrong. Which options in account I don't add, so account isn't visible in all places?


Solution

  • In short. Not fully configured SyncAdapter. If you don't want change contentAuthority of ours than just create one more sync adapter with different contentAuthority.

    Links to fix the problem.

    Display custom sync adapter as an option when adding contacts

    How to add my application's account to the Android Contacts application's "Accounts" list?

    https://android.googlesource.com/platform/packages/apps/Contacts/+/android-sdk-support_r11/tests/res/xml