Kotlin Generate VCF vCard Android Programmatically

Kotlin Generate VCF Programmatically for android app is not very complex task.

In this example, we will create vcf or vcard file from the information like name, mobile number, email id etc.

It is necessary to develop the vcf file when you want to share contact details from your app.

We have used kotlin language in this tutorial, if you want to use java then read how to make vcf file in android.

Final Result

Step 1. Adding permissions

Add below permissions in AndroidManifest.xml

We need these two permissions so that we can use storage resource of android device.

If your app’s target version is greater than 22, then you need to ask for runtime permissions.

Visit this tutorial to ask for the runtime permissions

Whole code for AndroidManifest.xml

Step 2. Upgrade Main Activity

Replace your existing code for activity_main.xml with the below one

There are three edittext in the layout file.

We will enter name, phone number and email id.

Our VCF or vCard file will contain these three information.

On the click of the button, vcf file would be ready in the fraction of second.

Source code for MainActivity.kt is as following

Step 3. Explanation of Main Activity

Checkout the below code

Above code will generate a folder named “vcf_demonuts” if it is not exist.

All the vcf files you generate, will be stored in this folder in internal storage of android device.

The name of the vcf file is decided by the below line

Here, we will fetch the current time as a name of vCard file.

It also includes millisecond so that always, unique name will be generated.

Following code will generate vcf file

So it was all the information for this tutorial.

If you have any trouble, then ask it in comment section.

Have a good day with your VCF file!

Download the source code for kotlin generate vcf example

[sociallocker]Download Kotlin VCF Source code[/sociallocker]

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *