Android Question Create VCF file

Mostez

Well-Known Member
Licensed User
Longtime User
I have a list of contacts (name, phone, ..) displayed on B4Xtable and I want to export selected item to VCF file and then use FileProvider to send it by email or whatsapp. how to create VCF file? and what is the mime type to use in this case?
 
This thread might help on the format of the file:

 
Upvote 0
thanks so much, it helped to understand how things go, never knew that it's just a type of text file, i opened presaved VCF with binary editor, it is easy to create, but still have one more problem with base64 picture encoding
Edit: i found it here
 
Last edited:
Upvote 0
There's a library for that:

 
Upvote 0
here is a quick start:
B4X:
Public Sub GenerateVCF() As String
    Dim SB As StringBuilder
    SB.Initialize
    SB.Append("BEGIN:VCARD").Append(Chr(0x0D)).Append(Chr(0x0A))
    SB.Append("VERSION:2.1").Append(Chr(0x0D)).Append(Chr(0x0A))
    SB.Append("N;LANGUAGE=en-us:;").Append(Chr(0x0D)).Append(Chr(0x0A))
    SB.Append("FN:").Append(ContactName).Append(Chr(0x0D)).Append(Chr(0x0A))
    SB.Append("ORG:").Append(CompanyName).Append(Chr(0x0D)).Append(Chr(0x0A))
    SB.Append("TITLE:").Append(JobTitle).Append(Chr(0x0D)).Append(Chr(0x0A))
    SB.Append("TEL;WORK;VOICE:").Append(WorkPhone).Append(Chr(0x0D)).Append(Chr(0x0A))
    SB.Append("TEL;HOME;VOICE:").Append(HomePhone).Append(Chr(0x0D)).Append(Chr(0x0A))
    SB.Append("TEL;CELL;VOICE:").Append(MobilePhone).Append(Chr(0x0D)).Append(Chr(0x0A))
    SB.Append("EMAIL;PREF;INTERNET:").Append(WorkEmail).Append(Chr(0x0D)).Append(Chr(0x0A))
    SB.Append("EMAIL;INTERNET:").Append(HomeEmail).Append(Chr(0x0D)).Append(Chr(0x0A))
    SB.Append("End:VCARD").Append(Chr(0x0D)).Append(Chr(0x0A))
    
    Return SB.ToString
    
End Sub
 
Upvote 0
Back
Top