Export to vCard

I’m working on a program that allows users to cycle through a variety of contacts in a list viewer. Once a user finds a contact that they want to establish a business relationship with, I want them to be able to export the contact to a vcard (vcf) file so that they can place the contact in their actual phone address book. Has anyone else done something like this? I’ve looked in the forum by I don’t see anything on this topic. I’m looking for a suggestion about how to do this. I have the format of the final file. I just don’t know how to get the info out of the app and into the file.

Any help would be greatly appreciated.

1 Like

Hi Jim,

Attempt #1: For a web app, you could include the VCF file as an app asset and open it with the web viewer. That causes chrome to download it. However, this approach doesn’t work in Thunkable Live on iPhone. You get the raw text in the Web Viewer screen instead - not useful. I don’t know about Android - I’ve just plugged my Kindle in to charge, so can update later. (UPDATE: At least on Kindle/Thunkable Live, it is completely unresponsive to being told to open link a .vcf file. Definitely go on to attempt #2)

Attempt #2: A better option might be this: Get the .vcf files on the internet somewhere. Then you can open them like this:
image

That causes the native contacts manager in iPhone to open the contact, and I can click ‘add contact’ at the bottom. It also triggers a download on the web app viewer. It works on Kindle (Android) as well.

I think option #2 is your solution. You just need to find some webspace to park your VCFs on.

1 Like

I understood it that he/she wants to create a .vcf file from the selected contact in the list viewer (with other details such as phone number) and then export it to the phone. I must have completely understand the issue in a wrong way.

I was thinking of developing functions in Thunkable to generate the file structure of .vcf file and then use a JavaScript script to save it. Good I did not start coding it.

2 Likes

I think it’s very possible that is what Jim wants. :slight_smile:

1 Like

I’d be interested to see this JavaScript wizardry. :slight_smile:

2 Likes

I do a lot of JavaScript codes but for this exact requirement, the Google sheet Marcos works better and can give the user a dialogue of where to save the file.

Muneer, you are correct. I do want to be able to export directly from the labels to a vcf file. That way I can make changes to the list and create a new vfc file for any new additions to it.

1 Like

At the request of @catsarisky I started with saving data to file.
It works OK from the browser and from Web Test but crashes on mobile Live Test.

I need to do some testing.

The vCard part is very easy.

This is my test project to save a file
https://x.thunkable.com/projectPage/60a172a49d5e640011cd9947

I’m now running the html file from web viewer. I will test running it from open link to check if it works from the mobile app.

1 Like


Agreed testing in Live/iPhone

1 Like

Can open the html file directly from your iPhone browser

https://3ynihrnjb7v5zcebdgtvag-on.drv.tw/sounds/Create-file.html?content-data=this-is-a-test&file-type=text/csv&file-name=just-a-file.csv

I tried switching your sample to open link. My iphone asked if I wanted to download, but then Safari didn’t know what to do with what it got, and I got a blank screen. Still getting closer! (I’m not sure my phone knows what to do with a csv?)

1 Like

I use Android and it saved the file correctly.

You can use .txt instead. I used .CSV just because my phone knows what to do with it.

Yeah, that’ll output a format my iPhone understands. Here’s a tweak on the project. It’s non-functional - doesn’t take actual values, but DOES write a .vcf that my phone understands.

https://x.thunkable.com/copy/a1936de4367b0b57aa888990a0058745

1 Like

Thanks @catsarisky

It’s after midnight my side. Tomorrow I will do the vcf parser.

1 Like

Where is the file saved? I just tried to open your project and it worked just fine but I don’t know where the file goes. I don’t need to be able to open the VCF file in the program I’m building. What I want to be able to do is export it to some place on their phone so that they can import the file into their address book. Ideally once the file is exported to the phone it would automatically open or show up in the address book.

1 Like

I’ll work on this tomorrow @jim.malmberg38

Once finished it should be prompted automatically on the user’s phone or at least this is the goal.

Hi Jim,

If you try the project I linked above, it’ll open a fake contact card – or at least, it does on iPhone, and then there’s an ‘add contact’ button at the end. :slight_smile: It’s proof of principle that it’ll work, not yet a working version.

Good night, @muneer! :slight_smile:

(updated - also on Android/Kindle, although I had to click ‘open’ after it downloaded.)

1 Like

@jim.malmberg38
@catsarisky

I updated the project to make it workable. I found that in Android, it did not accept the file after being downloaded. I can see it and see that all information is saved but the contact app on the phone doesn’t want to import it.

I searched in the net and found that a vCard file is not a text but it is actually a binary file (8 bit bytes or extended ASCII) so I had to try different file formats and found that my phone accepted the generated file when I used file type of application/octet-stream.

I need you to test it so we can say it works on different phones.

Export vCard

If it works, I’ll put it as part of the WDC so people can benefit from it.

Emoorted vCard Example

Good job @muneer, it works well for me.

1 Like

My iphone asks if it should download but does not open it. It’s possible you need some OS-specific code, since it was working for iphone yesterday.

Updated: Yep. My phone wants this as the file-type instead:

Also, I think you have first and last names reversed?

1 Like