2

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.

marmor
  • 27,641
  • 11
  • 107
  • 150
DuhVir
  • 447
  • 1
  • 4
  • 15
  • I don't understand the question, if you're seeing your app's contacts in the device's contacts app, and all those contacts are in your own account, then it sounds like it's all working. What do you think you're missing? BTW, have you read this: http://blog.udinic.com/2013/07/24/write-your-own-android-sync-adapter/ ? – marmor Mar 06 '18 at 08:17
  • I will read it now. About your question. Problem that I do it through my function SQlite2Contacts in manual mode. Function in first step removes contacts from ContactContract which doesn't exist in SQlite anymore. Than updates those which exist but changed and than create those which are not exsit. All this in my opinion waste process time for things that I think android can do much more faster and right. I just want that I do not touch ContactContracts and Android just get those data from my ContentProvider. if it's possible – DuhVir Mar 06 '18 at 08:23
  • got it, i'll put my thoughts as an answer – marmor Mar 06 '18 at 08:42

1 Answers1

1

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)

marmor
  • 27,641
  • 11
  • 107
  • 150
  • Thank you. So short answer is ContentProvider can't transparently provide data to ContacContract and my manual synchronization have no more "native" way. About turtorials(1 read one of them sync-adapter part) and in couple moments it's a bit outdated. I read official before and it's more useful for me. I just thought tat's more logical not edit ContactContract DB by hands, but just give it link to some sort of ContentProvider adapter which gets data when it need. Thank you once again. Say that direction wrong also helpfull and saving my time ) – DuhVir Mar 06 '18 at 08:58