Contact ids are not stable. To address a contact you need a contact
lookup uri. Your can build one or example with this function:
http://developer.android.com/reference/android/provider/ContactsContract.Contacts.html#getLookupUri(long,
java.lang.String)

After you can pass it to the contacts app.
BTW content://contacts/people/ is deprecated.

On 6 June 2012 11:34, Balint <[email protected]> wrote:
> I query the phone's calllog into a ListView. So when the user long clicks an
> item, a dialog comes up with options, including "View contact". To be able
> to view the contact the intent needs the contact id. From the calllog I get
> the contact id by the phone number.
> My problem is that I not always get to see the right contact. I click on
> Peter, and Peter's contact sheet comes up. I click on Sarah, and Jason's
> contact sheet comes up.
>
> I must have been using this code the wrong way. Please help.
>
>     ContentResolver contentResolver = getContentResolver();
>
>     Uri uri =
> Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
> Uri.encode(phone));
>
>     Cursor cursor =  contentResolver.query(uri, new String[]
> {PhoneLookup.DISPLAY_NAME, PhoneLookup._ID}, null, null, null);
>
>     if(cursor!=null) {
>        while(cursor.moveToNext())
>        {
>       String contactName =
> cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME));
>       contactid2 =
> cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup._ID));
>       }
>       cursor.close();
>     }
>
>     Intent intent_contacts = new Intent(Intent.ACTION_VIEW,
> Uri.parse("content://contacts/people/" + contactid2));
>      startActivity(intent_contacts);
>
> Maybe what I need is not the PhoneLookup._ID, but some other ID.
>
>  - on a HTC Desire HD (2.3.5) I get the proper contacts in 99% of the
>    cases.
>  - on a ZTE Blade (2.2) I get the proper contacts in 60% of the cases.
>  - on a Samsung Galaxy Ace (2.3.3) I get the proper contacts in 5% of the
> cases.
>
> What the hell is going on???
>
> --
> 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