Generate Vcf File Android Studio Programmatically

Hello, learners. Welcome to generate vcf file android studio programmatically example tutorial. 

We will learn how you can generate vcf file android studio programmatically from string resources.

VCF file also known as Vcard file.

Creating Vcard file in android app is an easy task.

This tutorial is helpful to you when you want to develop an app regarding contact details.

For example, when you want to share contact details which are given by user, this tutorial will guide you to bound those details in vCard file.

First check output then we will implement tutorial in the android studio.

Download Source Code

 

Creating generate vcf file android studio programmatically 

Step 1: Create a new project in Android Studio.

Always create a new project in Android Studio with empty activity.

Step 2: Updating AndroidManifest.xml file

 add required permissions between <manifest>….</manifest> tag.

We need these two permissions to read and write details from external storage of user’s mobile device.

Note: If you are targeting SDK version above 22 (Above Lollipop)  then you need to ask a user for granting runtime permissions.

Final code for AndroidManifest.xml file

 

Step 3: Updating activity_main.xml file

Copy below code in activity_main.xml file

Step 4: Preparing MainActivity.java class

Add following source code in MainActivity.java class

Step 5: Description of MainActivity.java

Following code will genereate a folder named “vcf_demonuts” if not existed.

Following line specifies name of the VCF or vCard file

Here, we will fetch current time as a name of vCard file. It also includes millisecond so that always, unique name will be generated.

Finally, below code will generate VCF or vCard file

If you want to open this newly generated vcf or vcard file programmatically,  then remove the comment from below snippet.

So all for generate vcf file android studio programmatically example tutorial.

Thank you and keep learning.

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...

2 Responses

  1. Saran says:

    how to add an image to v card?

  2. Rajender says:

    That generated Vcard file not shareable via sms.

    Please check once .
    How to share VCF file via sms.?

    could you please explain.

Leave a Reply

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