Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android vcard string to contact

i'm wondering if there's a clean way to import a vcard as an android contact. i have a vcard parser, but mapping each possible vcard field and field type is going to be a painful, bug-prone exercise. is there a better way?

an android contact looks suspiciously like a vcard, so i suspect they use vcards internally. there's no public API for this however.

like image 724
Jeffrey Blattman Avatar asked Jan 04 '11 23:01

Jeffrey Blattman


People also ask

How do I send a vCard to contacts?

Open the “Contacts” app and the contact that you want to transfer. At the bottom of the screen, tap the “Share” symbol. Select the option to share the contact via email and send the message (with a vCard attached) to your own email address. On the new phone, open the email and download the vCard file.

How do you text a vCard on Android?

On the Sharing Menu that appears, tap on Messages or any other App that you would like to use to Share Contact's vCard or VCF File attachment. 8. On the New Message screen, type Recipients Name, type your Message (if any) and then tap on the Send button to send the attached VCF file to the recipient.

Does vCard work on Android?

Importing vCard to Android can be so easy with the help of Dr. Fone - Phone Manager (Android). Besides importing . vcf file to your Android, you're able to backup your Android SMS, install APK file on your Android phone and tablets, backup, and restore all contents on your Android phone and tablets.


Video Answer


1 Answers

an android contact looks suspiciously like a vcard, so i suspect they use vcards internally.

I think it's a lot more complicated than using 'vCards internally' especially as vCard is effectively just a text file format making it inefficient to store and more so to search a large number of them.

The Overview of ContactsContract (note I cut it at the point it mentions 'three-tier data model')...

Overview

ContactsContract defines an extensible database of contact-related information. Contact information is stored in a three-tier data model:

As far as I can tell there is a way to 'extract' a vCard relating to an individual contact but I don't know of one to create a contact from a vCard.

EDIT: WRT importing vCards when clicking a link in a browser - yes, good point. I can confirm that it works when receiving a vCard by Bluetooth at least (which is, of course, quite logical). If I 'open' the vCard on my phone, I get a 'chooser' asking me if I want to use 'File Editor' or 'People' (the HTC contacts app - not sure if it's called the same on other phones). If there is only one vCard then it imports without further prompting. If there are more than one, I get another chooser asking if I want to import One/Multiple/All (Multiple gives another chooser with checkboxes to make my selection).

In theory I suppose, it might be possible to have a whole load of .vcf files dumped in a directory somewhere and write some code which simply creates an Intent to 'open' one of them and use that with startActivity() without specifying which activity to use. I'm not sure which intent action would be being used here but I would start with ACTION_VIEW - other choices might be ACTION_EDIT or (tenuously) ACTION_RUN.

Although this may work in a known environment particularly as a one off, it is a bit messy and behaviour/results may vary with different phones, versions of Android and contacts apps.

EDIT2: WRT to using an Intent to process .vcf files, I've only tried it from my SD card - I have no idea how to do it without saving it first. The following reproduces exactly what I see when I open a vCard that's sent via Bluetooth...

Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_VIEW);
i.setDataAndType(Uri.parse("file:///mnt/sdcard/downloads/bluetooth/MickeyMouse.vcf"), "text/x-vcard");
startActivity(i);
like image 165
Squonk Avatar answered Oct 04 '22 22:10

Squonk