Search code examples
androidadbcontacts

ADB - Open Contact Details by Phone Number


I am trying to open the contact details for an Android phone contact by their phone number in ADB.

The command

adb shell am start -a android.intent.action.VIEW content://contacts/people/

will open the contacts app, while

adb shell am start -a android.intent.action.VIEW content://contacts/people/1

will open up the contact details for the contact with CONTACT_ID equal to 1. I essentially want to do this same thing, only by passing in the contact's phone number, and not the contact ID. I suppose an error should be thrown, or the command should do nothing, if no contact exists with the given phone number.

I ask this because I am running certain adb commands on a KitKat device from an external testing suite, and do not have access to the Android API.

Is what I'm trying to do here even possible? Thanks!


Solution

  • The content://contacts provider has been deprecated for awhile. You should be using content://com.android.contacts instead.

    To find the proper contact_id to android.intent.action.VIEW for your phone number do adb shell content query --uri content://com.android.contacts/data/phones/filter/<phone number> --projection contact_id

    For more consistent results make sure to use phone number in normalized E.164 format.