Page 1 of 1

How to get number from name via content uri?

Posted: 04 Nov 2014 12:34
by ottodicatania
Hi,
how to get phonenumber from contactname via content uri like name from number - "content://com.android.contacts/phone_lookup/{phone_number}; projektion: display_name"?

thx

Re: How to get number from name via content uri?

Posted: 04 Nov 2014 18:27
by Martin
Hi,

number should work. You can also replace the variable in the content URI with an actual number and use the [...]-button of the projection field to see the name of the available columns.

Regards,
Martin

Re: How to get number from name via content uri?

Posted: 04 Nov 2014 18:52
by ottodicatania
Moin,
I know but i search for a way to get number as result when giving then name of the contact as var.
Danke!

Re: How to get number from name via content uri?

Posted: 04 Nov 2014 19:52
by Martin
Hi,

I don't particularly like the contacts database so I might be wrong but I think you will need to execute two queries. A first one to find the contact ID and a second query to look up the numbers.

Content URI: content://com.android.contacts/contacts
Projection: _id
Selection: display_name like 'Test Name' and has_phone_number=1
Result type: Single value
Variable: contact_id

To get the list of numbers for the contact:
Content URI: content://com.android.contacts/data/phones
Projection: data1
Selection: contact_id={contact_id}
Result type: List
Variable: numbers

To get only the primary number of the contact:
Content URI: content://com.android.contacts/data/phones
Projection: data1
Selection: contact_id={contact_id} and is_primary=1
Result type: Single value
Variable: number

Regards,
Martin

Re: How to get number from name via content uri?

Posted: 05 Nov 2014 10:28
by ottodicatania
<spock>fazinierend<\spock>
Es funktioniert, vielen Dank!
Andreas