vendredi 29 mai 2015

sqlite android extract contacts with phone number

I'm facing this sqlite issue in which I'm trying to extract the contacts that have phone number/s with the 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 is that in the case that the contact has more than 1 phone number the result will be in this 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 is undesirable because of the duplicate data.

I want to make only 1 query to the db that hopefully can be written to return the result like this:

id: 451, name: Maria, photoUri: null, has_phone_number: 1, phone_number: 0700 000 000, 0800 000 000, 0900 000 000

Is it possible?

Thank you.

Aucun commentaire:

Enregistrer un commentaire