user5225979
user5225979

Reputation:

How to save vcard from qr code to contacts

I need to save to contacts if the qr code contains v card. I was trying to do that with this library but I could not read the v card information, I don't know which method is to use for that. I have seen a lot other similar posts but unfortunately those couldn't save me. I am using zxing library to read qr codes.

Upvotes: 2

Views: 7221

Answers (1)

Mister Smith
Mister Smith

Reputation: 28158

vCard is actually a bit verbose. You can use the MECARD format instead.

Here you can see an example string from the ZXing Wiki:

MECARD:N:Owen,Sean;ADR:76 9th Avenue, 4th Floor, New York, NY 10011;TEL:12125551212;EMAIL:[email protected];;

Now for the vCard format, I can see there's a class named VCardResultParser in the ZXing javadoc, and apparently it supports vCard v2.1. I made this small example stripping down some fields from the example in the wikipedia page for vCard:

BEGIN:VCARD
VERSION:2.1
N:Gump;Forrest
ORG:Bubba Gump Shrimp Co.
TEL;WORK;VOICE:555
ADR;HOME:;;42 Plantation St.;Baytown;LA;30314;USA
EMAIL;PREF;INTERNET:[email protected]
END:VCARD

In both cases, you just have to serialize the fields to a plain text string and then you encode it onto a QRCode as usual. I tested both examples with a Samsung phone and when you scan them with ZXing, the leftmost button allows you to add a new contact. The contacts app opens, you press the "+" button and a new contact is created with the provided fields filled up.

Upvotes: 5

Related Questions