Replies: 3 comments 4 replies
-
|
I copied RawContactToNewRawContact.kt and made newCopy public with a companion object, which does most of the heavy lifting except for group memberships, which have to be added manually. |
Beta Was this translation helpful? Give feedback.
-
|
Hey @slowcar, thanks for considering this library 😀
Yes. The only way to insert new Contacts is by inserting new RawContacts. This is the case even if you do not use this API and instead use
Attempting to create a Contact row directly will not work and will result in error. Other libraries that attempt to abstract away the "RawContacts" construct and only expose "Contacts" constructs are inherently incorrect. I know this from experience because before I made this library public, thats how I initially designed the public facing API. I thought that it would make the library a lot easier for users to use if they did not have to deal with "RawContacts". You can see this if you go far back enough in the commit history. I encountered so many issues that I almost abandoned the project before making it public! I pretty much had to rewrite the entire library. |
Beta Was this translation helpful? Give feedback.
-
IMO, it would be better to backup RawContacts directly instead of dealing with Contacts. For backup, you can use the RawContactsQuery API to get all the RawContacts. Then convert them to JSON (or whatever serialization you want to use) and save them to a local or remote file. For restore, you can then use the Insert API to insert the RawContacts.
A "Contact" is a different construct from a "RawContact". All "Data" belong to "RawContact". Each Contact can be made up of one or more RawContacts. I wrote about this in the Contacts Provider / ContactsContract Basic Concept. The data a Contact has is simply a reference to data from one of its RawContacts. For example, the Contact display name is automatically set by the Contacts Provider based on one of its RawContact's data (name, email, etc...). If you use RawContacts directly in your backup/restore algorithm, you should not need to "convert a Contact to a NewRawContact". |
Beta Was this translation helpful? Give feedback.


Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
i would like to use your library to backup and restore contacts.
Looking at the Insert API it seems that i have to use NewRawContact objects to insert.
Would it be possible to insert Contact objects (deserialized from json, from example), or is there any way to convert a Contact to a NewRawContact without copying each field manually?
Cheers,
Simon
Beta Was this translation helpful? Give feedback.
All reactions