How to open a contact card in Android by ID

Java_Waldi picture Java_Waldi · Nov 25, 2010 · Viewed 12.5k times · Source

Is it possible to open an android contact card by contact's ID? It works with the phone-number. Here is an example, if I use

Intent i = new Intent();
i.setAction(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT);
i.setData(Uri.fromParts("tel", "123456", null)); //<---- Change here from Phone to IDcontext.startActivity(i);

But I want to open this contact card by ID, for example if the phone-number from the contact would change.

Answer

Thorstenvv picture Thorstenvv · Nov 25, 2010

use ACTION_VIEW and either build a contact URI using the contact ID or use the contact lookup URI if you already have it (preferred).

    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactID));
    intent.setData(uri);
context.startActivity(intent);