Search code examples
androidandroid-intentcontactscontract

how to open native contact card by URI


Can someone please explain me how to open contact native for specific contact URi

I manage to resolve the contact URI by:

Uri lookupUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
                Uri.encode(displayName));

and then I tried do this:

     Intent intent = new Intent(Intent.ACTION_VIEW);
     intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
     intent.putExtra(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, "555");
     context.startActivity(intent);

but it's only open the native address book without any resolving


Solution

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

    You can retrieve the contactId by browsing using contentResolver:

    id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
    name = cur.getString( cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
    Log.d(tag, "Id: "+ id+"\t Name: "+name);