检查联系人是否已在...上更改 LOOKUP_KEY 希望它会有所帮助,因为android文档很难遵循I am trying to sync user phone numbers to firestore. It seems to work but when i delete a contact from my phone, it seems like some other contacts id's are being replaced, causing unnecessary deletion and creation to firestore. My only clue is that these contacts mostly around id 120,000. Is it normal? What is goung on?This is how i get new created contacts, lcid is the last-contact-id registered to firestore:private fun getNewContacts(): Cursor? { val projection = arrayOf( ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.HAS_PHONE_NUMBER) val selection = ContactsContract.Contacts._ID + "> ?" val selectionArgs = arrayOf(mFireContactDetails!!.lcid.toString()) val sortOrder = ContactsContract.Contacts._ID + " ASC" return mContentResolver.query( ContactsContract.Contacts.CONTENT_URI, projection, selection, selectionArgs, sortOrder)}This is how i get the deleted contacts, ldel_ms is the last deleted timestamp registered to firestore:private fun getDeletedContacts(): Cursor? { val projection = arrayOf( ContactsContract.DeletedContacts.CONTACT_ID, ContactsContract.DeletedContacts.CONTACT_DELETED_TIMESTAMP) val selection = ContactsContract.DeletedContacts.CONTACT_DELETED_TIMESTAMP + "> ?" val selectionArgs = arrayOf(mFireContactDetails!!.ldel_ms.toString()) val sortOrder = ContactsContract.DeletedContacts.CONTACT_DELETED_TIMESTAMP + " ASC" return mContentResolver.query( ContactsContract.DeletedContacts.CONTENT_URI, projection, selection, selectionArgs, sortOrder)}Next is a log example. When i delete a contact it is recognized as deleted but also other random contacts replacing their ID (i did not mention the log names)values retrieval successnew contacts detectedadding 120797adding 120803adding 120804adding 120805adding 120806adding 120807adding 120808adding 120809adding 120810sync new contacts successdeleted contacts detecteddeleting contact id: 119576deleting contact id: 120798deleting contact id: 120799deleting contact id: 120800deleting contact id: 120801deleting contact id: 120802deleting contact id: 119762deleting contact id: 119700deleting contact id: 119561deleting contact id: 119613sync deleted contacts success 解决方案 From the documentations and articles it seems that android can sometimes change the contact id, this is very strange and un-expected but makes sense after my many weeks and attempts trying to solve this issue.From what i can understand, the reasons are quite diverse so i can guess also in my case when one change or delete of contact can change other contact id's.It seems that to overcome, i need to use the `LOOKUP_KEY, which i yet to understand how.Some documentations includes:Detecting changes in android contactsCheck if contact has been changes on...LOOKUP_KEYHopes it helps since the android documentations are so hard to follow 这篇关于在Android上删除联系人时,其他随机联系人的ID已更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-12 11:47