-
Hello! Is it possible to obtain a unique identifier using this library, that works across devices? My use case is to create an app to automatically delete contacts after a given time (temporal contacts), and I wanted to do it online so user can keep it on multiple devices... Is it even possible? Is there a unique "identifier" for contact across devices? |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
Hey @alorma 👋 Thanks for asking this question! I need to do a bit of research first before I give you a concrete answer. I think #39 will help answer this question. I'll work on it as soon as I can! The closest thing to this "ID that could be used to identify contacts across devices" is https://developer.android.com/reference/android/provider/ContactsContract.ContactsColumns#LOOKUP_KEY because it has to do with syncing and aggregation. I created issue #140 to add support for it. I just included in the v0.1.10 Release Checklist 🔥 What I can say right now is that anything that the Android Open Source Project (AOSP) Contacts app (the Contacts app that comes with every copy of Android) can do, this library will also allow you to do. If AOSP Contacts can do something that this library can't do for you, let me know and I will make sure that there is an issue for it so I can implement it 😁 In the meantime, @alorma could you tell me the exact steps you want to accomplish? Is it something like this...?
If this is what you want to do, then you can already do it with this library. But first, keep in mind that depending on the Account sync settings in the device, any Contact you create on one device will be available on all your devices that are logged in to the same Account (e.g. [email protected]) with Contact syncing enabled. The same thing applies for when you delete a Contact. Deleting a Contact on one device will also delete it in other devices. But, all of this depends on the system sync settings for the account for each device. Users can be offline or they turned off Contact syncing. A lot of things can go wrong. Contacts are not guaranteed to be synced at all times. Another thing you should know is that Contact data is synced across all devices via sync adapters interfacing with a remote backend server. In the case of google accounts (e.g. [email protected]), Google sync adapters in the device manage syncing Contact data across devices by getting and setting data from/to Google servers. Google servers are the source of truth and contain all Google Contacts. This library does not provide a way for you to interact with Google backends servers or any other backends.
Anyways, if you are still looking to implement a feature that automatically deletes contacts created after a certain amount of time... Using this library, it might look something like... fun createTemporaryContact(newRawContact: NewRawContact, deleteOnDate: Date) {
val contactsApi = Contacts(context)
val insertResult = contactsApi.insert().contacts(newContact).commit()
val contactId = insertResult.contact(contactsApi, newRawContact)
deleteContactOnDate(contactId, deleteOnDate)
}
fun deleteContactOnDate(contactId: Long, deleteOnDate: Date) {
// Use work manager or something to schedule running a job to delete the contact on the given date.
} Once #140 has been implemented, you should use the Contact Notice that this is all client-side code. It's all code in your Android app/service. Syncing changes (inserts, deletes, updates) across devices are done automatically by the Contacts Provider, depending on Account Contact sync settings. |
Beta Was this translation helpful? Give feedback.
-
Cool! That is helpful! I guessed that it worked that way on sync across device. My concer was If i create a contact and save on some online database for my app (example: Firebase) so I can get the same data on mutiple devices. BTW, I will start interacting only on local so for now I will not worry much on syncing, just exploring the possibilities for now! Thanks |
Beta Was this translation helpful? Give feedback.
-
I would highly advice you NOT to do this. The Contacts Provider along with Account sync adapters manage all Contact data in their own online database. If you save a copy of Contacts in your own database, it will quickly get out of sync with the Account online database.
This library only documents the syncing behavior. It currently does not provide syncing functions. You would need to implement your own sync adapters, which is currently not in scope of this library. I'll work on #39 before I close this issue. As I mentioned, you can use the |
Beta Was this translation helpful? Give feedback.
-
Cool, thanks |
Beta Was this translation helpful? Give feedback.
-
@alorma, I did some testing. It seems like the I will close this issue once I've completed; Thanks for raising this issue! |
Beta Was this translation helpful? Give feedback.
-
I'll actually close this issue now that I've completed documentation in #39. Keep an eye out for the progress on #140 if you are interested in using lookup keys 😁 |
Beta Was this translation helpful? Give feedback.
@alorma, I did some testing. It seems like the
LOOKUP_KEY
is the same across devices as long as data has been synced (up-to-date) with the servers!I will close this issue once I've completed;
Thanks for raising this issue!