Use the PhoneLookup table for this.
http://developer.android.com/reference/android/provider/ContactsContract.PhoneLookup.html

String phoneNumber = // the given number

1. Make the URI to the contact:
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(phoneNumber));

2. Get your row(s):
Cursor cursor = contentResolver.query(uri, new
String[]{PhoneLookup.LOOKUP_KEY, PhoneLookup._ID}, null, null, null);

3. Check the result:
if (cursor != null && cursor.moveToFirst())
{
cursor.getString(0) will be your lookup key and cursor.getLong(1) is your
contact id in the aggregated contact table.
}
else
{
 // no contact found
}

ps: dont forget to close your cursor

On 23 May 2011 13:22, b_t <[email protected]> wrote:

> It returns only one row for a selected phone number. The URI contains
> the condition after the lookup key.
> This URI is returned by the phone number selection activity.
>
> On May 23, 9:39 am, Zsolt Vasvari <[email protected]> wrote:
> > I take that back.  I actually don't know if that query will work or
> > not.  I always just use ContactsContract.Contacts.CONTENT_URI and give
> > it a WHERE clause and a key and it works with the CONTACT_ID column.
> >
> > On May 23, 3:23 pm, Zsolt Vasvari <[email protected]> wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Your query will return the entire contacts database since you don't
> > > have a WHERE clause and a key.
> >
> > > On May 23, 3:03 pm, b_t <[email protected]> wrote:
> >
> > > > Hi,
> >
> > > > I try to pick a contact number by:
> >
> > > >                 Intent intent = new Intent(Intent.ACTION_PICK,
> > > > Contacts.CONTENT_URI);
> >
> > > > intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
> >
> > > > And I try to get a contact from the result by:
> >
> > > >                 Uri contactData = intent.getData();
> >
> > > >                 ContentResolver cr =
> getContext().getContentResolver();
> > > >                 Cursor c = cr.query(uri, new String[] {
> Data.CONTACT_ID,
> > > > Data.LOOKUP_KEY, Phone.NUMBER }, null, null, null);
> >
> > > > And in some devices or for some contacts it throws:
> >
> > > >                 java.lang.IllegalArgumentException: Invalid column
> > > > contact_id
> >
> > > > The URI is for example:
> >
> > > >
> content://com.android.contacts/contacts/lookup/812i70704be008e61b18/694
> >
> > > > Is it possible that CONTACT_ID column doesn't exist?
> >
> > > > Thanks, Tamás- Hide quoted text -
> >
> > > - Show quoted text -
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to