Search code examples
androidadb

Android - Importing contacts through vCards via ADB


I am currently trying to automate some Android actions through ADB and getting stuck with the contact import through vCards. There are 2 ways of doing this :

  1. automate the exact "tappings" of the user, which supposes you have to determine the position of each "button" according to the screen resolution, etc. It is what I have done right now but it really seem hard to maintain, since there are too much parameters to take into account (custom roms, wierd resolutions, portrait/landscape mod, etc).

  2. find what's happening when you click on "import contact from vCards" and do this action through ADB

Basically, I would like to apply the 2nd option, but I don't know what is happening when you click on "import contacts from vCard", which I would need to call the same action/intent from ADB. Any idea on the ADB command I should execute ?


Solution

  • Try this. Update -d option with correct vcf path.

    adb shell am start -t "text/x-vcard" -d "file:///sdcard/contacts.vcf" -a android.intent.action.VIEW com.android.contacts
    
    • Mime Type : text/vcard or text/x-vcard
    • URI: path to vcard
    • Action: android.intent.action.VIEW
    • Package: com.android.contacts