DuhVir
DuhVir

Reputation: 481

Provide contacts from ContentProvider to standard Contact app

I've tried to search, but I even can't ask the question in short form.

  1. I have SQLite table with id/username/mobile/email.
  2. I've created ContentProvider for it.
  3. I've created Account through AccountManager(AccountAuthenticator)

All of it working and I can create contacts using my function Sqlite2Contacts. I.e. each of SQLite record I provide to ContactsContract with my Account name and type. All contacts visible through standard application and when I remove account all contacts also removed.

All working fine, but... I think I've missed something. I suppose that should be some framework for It.

I.e. I bind my ContentProvider to... something using some sort of adapter without manual contacts synchronization.

I need the only answer can I do it or no, not implementation. And if I can... what class/framework/adapter should I use.

Upvotes: 2

Views: 341

Answers (1)

marmor
marmor

Reputation: 28171

Sounds like you're in the wrong direction, you should not be putting your app's contacts in a ContentProvider.

To put app specific contacts in the Contacts DB in Android your app needs two components: Account and SyncAdapter.

The Account allows the user to authenticate (if needed) and to manually remove / sync your app's contacts. The SyncAdapter is called by the system or programatically by your app and syncs RawContacts into the Contacts DB under your app's ACCOUNT_TYPE + ACCOUNT_NAME.

There are two tutorials by Udi you can follow:

And the official tutorial here:
https://developer.android.com/guide/topics/providers/contacts-provider.html
(under How to write a sync adapter for synchronizing data from your server to the Contacts Provider)

Upvotes: 1

Related Questions