android - How to detect a duplicate contact when Inserting a new one? -
After a contact backup application, I save all the information in a CSV file, and then I need to restore it back for. It works great, although if I press again twice, then it duplicates all the contacts. I tried the following code to remove the duplicate, it works but fails in some cases. Basically this fails when there is no explicit DISPLAY_NAME, for example if a contact contains only one phone number and is the phone number for DISPLAY_NAME, or similar to an email address. . I can not understand why this habit is always working since it appears that the DISPLAY_NAME area is the phone number / email address here is the code that I used to: Although I have seen that, if I click on contacts Produce. The same device / emulator, duplicate is detected, when I restore the same contact again, when it comes to devices, it seems that one reason does not work that at some point special symptoms are removed. For example, the display name "John Do" is read from CSV, but when it is inserted, it becomes "John Doe" and I can not see that "." Ever been snatched. What happens depends on the version of Android that the device is running. If the version is Honeycomb (3.0) or later, the contact name will be always , the name field is DISPLAY_NAME_PRIMARY, and if there is no name in any raw contact, then this field will be sent to a phone number or email address Has been set. It is difficult to know what is happening with your code because I can not tell how you are calling the contacts in all cases. But my guess is that you are looking at DISPLAY_NAME when you might want to view DISPLAY_NAME_PRIMARY. As a side comment, what you are trying to do here is full of risks. The contact provider is a complex system, and it can have many problems under the road in support of CSV. A better strategy is to run a sync between a contact provider and a cloud-based Google Contacts app.
Private Boolean contactExists (String DisplayName, string emailstring, string phonestring) {cursor CRSR = BA.applicationContext.getContentResolver (). Query (ContactsContract.Contacts.CONTENT_URI, New String [] {"display_name", "_ id"}, "display_name =?", New string [] {displayname}, null); While (crsr.moveToNext ()) {Hashmap m = new Hashmap (); {M.put (crsr.getColumnName (col), Integer.valueOf (col)) for; Col & LT; crsr.getColumnCount (); integer col = 0 col ++); } Int id = crsr.getInt (((integer) m.get ("_ id")). IntValue ()); String Email = GetEmails (ID); String Phone = GetPhones (ID); If (email content aquals (email string) & amp; phone content aquals (phishing)) {crsr.close (); Back true; }} Crsr.close (); return false; } Update: I tried with DISPLAY_NAME_PRIMARY with the same result
Comments
Post a Comment