sqlite android extract contacts with phone number -


i'm facing sqlite issue in i'm trying extract contacts have phone number/s following query:

cursor cursor = context.getcontentresolver().     query(contactscontract.commondatakinds.phone.content_uri,             new string[]{                 contactscontract.commondatakinds.phone.contact_id,                 contactscontract.commondatakinds.phone.number,                 contactscontract.contacts.display_name,                 contactscontract.contacts.photo_uri             },             contactscontract.contacts.has_phone_number + ">?",             new string [] {"0"},             contactscontract.commondatakinds.phone.display_name + " asc"     ); 

the problem in case contact has more 1 phone number result in form:

id: 451, name: maria, photouri: null, has_phone_number: 1, phone_number: 0700 000 000 id: 451, name: maria, photouri: null, has_phone_number: 1, phone_number: 0800 000 000 id: 451, name: maria, photouri: null, has_phone_number: 1, phone_number: 0900 000 000 

which undesirable because of duplicate data.

i want make only 1 query db can written return result this:

id: 451, name: maria, photouri: null, has_phone_number: 1, phone_number: 0700 000 000, 0800 000 000, 0900 000 000 

is possible?

thank you.

i don't think possible want do, workaround using hashmap. can handle thousands of entries, don't worry.

    cursor cursor = getcontentresolver().query(contactscontract.commondatakinds.phone.content_uri,             new string[]{ contactscontract.commondatakinds.phone.contact_id,                     contactscontract.commondatakinds.phone.number,                     contactscontract.contacts.display_name,                     contactscontract.contacts.photo_uri },             contactscontract.contacts.has_phone_number + ">?",             new string [] {"0"},             contactscontract.commondatakinds.phone.display_name + " asc");      map<string, list<string>> phonespercontact = new hashmap<>();     if (cursor.movetofirst()) {         {             string name = cursor.getstring(2);             string phone = cursor.getstring(1);              if (!phonespercontact.containskey(name)){                 phonespercontact.put(name, new arraylist<string>());             }              phonespercontact.get(name).add(phone);         } while (cursor.movetonext());     }      (string name: phonespercontact.keyset()){         //do whatever want contact , list of phones          list<string> phones = phonespercontact.get(name);         log.i("test", "name: " + name + ", numbers: " + phones.tostring());     } 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -