How to get number from name via content uri?

Post your questions and help other users.

Moderator: Martin

Post Reply
ottodicatania
Posts: 7
Joined: 02 Nov 2014 20:52

How to get number from name via content uri?

Post by ottodicatania » 04 Nov 2014 12:34

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

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

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

Post by Martin » 04 Nov 2014 18:27

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

ottodicatania
Posts: 7
Joined: 02 Nov 2014 20:52

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

Post by ottodicatania » 04 Nov 2014 18:52

Moin,
I know but i search for a way to get number as result when giving then name of the contact as var.
Danke!

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

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

Post by Martin » 04 Nov 2014 19:52

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

ottodicatania
Posts: 7
Joined: 02 Nov 2014 20:52

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

Post by ottodicatania » 05 Nov 2014 10:28

<spock>fazinierend<\spock>
Es funktioniert, vielen Dank!
Andreas

Post Reply