Android Question QR Code Vcard

james_sgp

Active Member
Licensed User
Longtime User
Hi, has anyone got any insight in how to make a Vcard QR Code; i.e. so someone can scan the QR Code and it inserts your details into their contacts list? Plenty of websites offer such a function, but I`d like to make a small app for creating it on the phone?


James
 

JohnC

Expert
Licensed User
Longtime User
Well, a QR code is just text encoded into an QR Code image. You can use this lib to generate a QR Code image from a string of text:


Now, the hard part is to create the proper string of text to generate the QR code from. A quick search for the Vcard format found this:


I noticed a note on that page saying "They have to be separated through line breaks".

So, maybe if you create a string that is formatted like this (using line breaks between lines):

BEGIN:VCARD
VERSION:3.0
N:Lastname;Surname
FN: Displayname
ORG:EVenX
URL:http://www.evenx.com/
EMAIL:[email protected]
TEL;TYPE=voice,work,pref:+49 1234 56788
ADR;TYPE=intl,work,postal,parcel:;;Wallstr. 1;Berlin;;12345;Germany
END:VCARD


Then generate a QRCode from that string, it might work!
 
Last edited:
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
Great thanks, now giving it a try. Your research was faster than mine, I was looking at how they do it in PHP, to learn...haha
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
Ok, gave it a try... it makes a pretty huge QR code and when I scan it with my phone it does open Contacts but the information is not transfered?

I`m building the string mentioned above with stringbuilder.

B4X:
    Dim sb As StringBuilder
    sb.Initialize
    sb.Append("BEGIN:VCARD")
    sb.Append("VERSION:3.0")
    sb.Append("N:Costello;James")
    sb.Append("FN:James Costello")
    sb.Append("ORG:xxx")
    sb.Append("URL:http://xxxxxxxx/")
    sb.Append("EMAIL:xxxxxxxxx")
    sb.Append("TEL;TYPE=voice,work,pref:xxxx")
    sb.Append("ADR;TYPE=intl,work,postal,parcel:;;xxxx;;;xxxx;xxxxx")
    sb.Append("End:VCARD")   
    
    Dim qr As QRGenerator
    qr.Initialize(my_qr.Width)
    my_qr.SetBitmap(qr.Create(sb.tostring))
 

Attachments

  • 1.png
    1.png
    57.8 KB · Views: 273
Upvote 0

JohnC

Expert
Licensed User
Longtime User
It doesn't look like you have line breaks between each line. You might try adding a Chr(10) character at the end of each line.
B4X:
sb.Append("BEGIN:VCARD" & Chr(10))
 
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
And just for kicks and giggles, try creating the string using the old fashioned way:
B4X:
"Line1" & Chr(10) & "Line2" & ....ect

...instead of using SB - just to see if the code is smaller.

Or maybe add this to see what the resulting string looks like:
B4X:
Log (SB.Tostring)
 
Last edited:
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
Ok, seems like there is something wrong in the Address line as it works with that line removed.

B4X:
    sb.Append("BEGIN:VCARD" & Chr(10))
    sb.Append("VERSION:3.0" & Chr(10))
    sb.Append("N:Costello;James" & Chr(10))
    sb.Append("FN:James Costello" & Chr(10))
    sb.Append("ORG:xxx" & Chr(10))
    sb.Append("URL:xxx/" & Chr(10))
    sb.Append("EMAIL:[email protected]" & Chr(10))
    sb.Append("TEL;TYPE=work:xxxx" & Chr(10))
'    sb.Append("ADR;TYPE=postal:xxxx;xxxx;;xxxxxx;xxxxxx" & Chr(10))
    sb.Append("End:VCARD")
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Also, I'm pretty sure that if you stuff less info into the Vcard string (like only your name, email and phone), the resulting QR Code will be much smaller.
 
Upvote 0
Top