2

I have data of contact locally in the app, I want to create a contact object and share it as v-card or vcf file to other phone using whatsapp, facebook etc.

Most of the solutions are based on getting contacts from contacts list and then sharing those, but in my case I have to create it programmatically.

1 Answers1

3

There's no built-in support to create vcards in Android, unless the contacts are already stored in Android's Contacts DB.

You can use the ez-vcard library for Android, here's an example usage snippet from the lib's readme:

VCard vcard = new VCard();

StructuredName n = new StructuredName();
n.setFamily("Doe");
n.setGiven("Jonathan");
n.getPrefixes().add("Mr");
vcard.setStructuredName(n);

vcard.setFormattedName("John Doe");

String str = Ezvcard.write(vcard).version(VCardVersion.V4_0).go();
marmor
  • 27,641
  • 11
  • 107
  • 150