0

I'm getting contacts from my phone but getting duplicate contacts.

public  void getAllContacts(ContentResolver cr) {
    Set<String> phonenumbersList = new HashSet<String>();
   phones = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");

    while (phones.moveToNext())
    {
        String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME ));
        String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
        System.out.println(".................."+phoneNumber);
        name1.add(name);
        phno1.add(phoneNumber);
    }

    phones.close();
}

please help me out.Help will be appreciated! Thanks!

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • Possible duplicate of [How to avoid duplicate contact name (data ) while loading contact info to listview?](http://stackoverflow.com/questions/25012061/how-to-avoid-duplicate-contact-name-data-while-loading-contact-info-to-listvi) and [how to remove duplicate contacts from arraylist](http://stackoverflow.com/q/22959625/6334037) – Jitesh Prajapati Sep 10 '16 at 05:46
  • ianhanniballake GM ,saw your recent fileprovider ,was great. maybe happening due to multiple account collision plus please don't follow the @user13 answer it's useless in most cases and slow – Pavneet_Singh Sep 10 '16 at 05:50
  • 1
    Well, what do you want to happen when there is a single contact with two phone numbers? Hide the second number? Make one row that has multiple numbers associated with it? Show two separate rows with the same contact name but different phone numbers? This is a fundamental question your app needs to handle and not something we can decide for you. – ianhanniballake Sep 10 '16 at 05:54
  • i want to show only one row with number....i don't want second num. – Praveen Reddy Sep 10 '16 at 10:34

0 Answers0