views:

269

answers:

1

In my application when a user clicks on a button I want to open the contacts application and display a particular contacts information.

At the minute I have this:

Intent intent = new Intent(Intent.ACTION_VIEW, People.CONTENT_URI);
startActivity(intent);

This displays the contact application with all the contacts displayed.

But how do I get it to display just one contact according to the contacts name or number?

This Code works: (answer)

Uri contactUri = ContentUris.withAppendedId(People.CONTENT_URI, 23);

Intent intent = new Intent(Intent.ACTION_VIEW, contactUri);
startActivity(intent);
+1  A: 

Append the contact ID number to the end of the URI.

For instance content://contacts/people/615

or People.CONTENT_URI + "/" + contactId

The ID number will come from your original contact query.

Jim Blackler
I cant append a string or int to the Uri though? Nor can I use the String "content://contacts/people/615" as an argument for the intent?
Donal Rafferty
Got it using this - Uri contactUri = ContentUris.withAppendedId (People.CONTENT_URI, 23); Thanks
Donal Rafferty
Yes, my apologies, my snippet won't actually compile. Glad you got it working.
Jim Blackler