If you visit my homepage schmid.pro using a mobile device, you will see that the design is slightly different. Plus, you will be able to download my vCard.
By default, if you don’t specify anything, Apache is not able to understand the .vcf extension, and serves the file as plain/text, which is bad!
Android sees it as a text file and lets the browser open it instead of opening the Contact application. Same as for the iPhone. I had to find a workaround.
Serve a vCard for Android
Android is able to handle vCards, as long as their mime-type is text/x-vcard. The easy view is to add this type to your htacces file and an Android user will have his contact application opened up when he clicks on your vCard file!
1 2 | ForceType text/x-vcard Header set Content-Disposition attachment |
Serve a vCard for iOS/iPhone
As usual when Steve decided that you cannot do something, you cannot find a workaround. Well… Steve decided it is not worth being able to download a vCard from the browser…
There is no easy way to enable the iPhone user to download your vCard and add it to its contact list.
But there are some hacks you can use.
The first one is
- Detect the iPhone
- Asks the user his email address
- Send him your vCard by email
Believe it or not, the Mail app is able to handle vCards, but not Safari.
The second one is to create a Google Places entry, because the Google Maps application can handle Google Places.
1 2 3 | RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} .*Mobile.*Safari
RewriteRule ^(.*)vcard.vcf$ http://maps.google.com/maps.... |
I currently implemented none of them on my site. I don’t know if iPhone users are worth the effort
You can try to download my vCard.
When I visit your site, I do not see your vcard on my android phone.
Is this working now?
Tried all kinds of .htaccess changes with no luck.
You are right. I replaced the link to my vCard by a link to my résumé. I forgot to change this post.
The file is still there, and it should still work: http://jonas.schmid.pro/Jonas_Schmid.vcf
I just had this issue for hours trying all the fixes.
I’m pushing out vCards as attachments from a database using php and mysql. I couldn’t use htaccess to change the type or content-disposition because I was already using it for a rewrite and other things and there’s a bunch of php code to get the data from the database.
I have php headers stating the text/x-vcard and utf-8 and attachment etc. but the problem was the version of vCard. I had it set at version 3, and after many searches I found that the current android only supports up to 2.1. I set it to 2.1 and now it’s all good. I didn’t need any version 3 functions so no worries.
Hope that helps someone.
Thanks for the tip!
Thanks for the article! Depressing but helpful.
Paul, when using vcard 2.1 does it work natively on Android (I mean without download > open in contacts)? If it does, where do you create vcf 2.1 vcards?
I have just published an alternative solution on my blog which describes how to attach the contact file as an attachment to a calendar file which is handled by mobile safari
http://mobicontact.info/iphone/download-contact-from-web-page/
This can be used to download the file to your SD card
Tested with Android version 4.0.3 only
======= php =========================
======= html ========================
Download vCARD
The bulk of my comment disappeared and seems to be in a file!! I’ll repeat it here without the opening line of php
Tested with Android version 4.0.3 only
======= php =========================
// this php file (example saved as name is vCardDL.php is placed in my html subdirectory
//
header(‘Content-Type: application/octet-stream’);
// the above line is needed or else the .vcf file will be downloaded as a .htm file
header(‘Content-disposition: attachment; filename=”xxxxxxxxxx.vcf”‘);
//
//header(‘Content-type: application/vcf’); remove this so android doesn’t complain that it does not have a valid application
readfile(‘../aaa/bbb/xxxxxxxxxx.vcf’);
//The above is the parth to where the file is located – if in same directory as the php, then just the file name
======= html ========================
Download vCARD
I am afraid your link to download your vCard is wrong:
http://dev.schmid.pro/android/vCardDL.phpp leads to a 404 error.
same with http://dev.schmid.pro/android/vCardDL.php
I would be very interested to check if this approach works. You can put dummy data to protect your privacy, if you prefer.
thanks
Giuliano
Hi Jonas, your posts are very helpful for me to begin to understand how to use vCards with a website. Could you tell me how to do the “mime-type is text/x-vcard” bit from “Serve a vCard for Android” in your original post? I use Nearly Free Hosting for my minimalist business site, and I know how to use Fetch (my Mac FTP client) to get to my Public directory, my Home directory, and Root. Unfortunately, I have no idea what an “htacces file” is or where it might be located.
I’ve put my vCard in my public directory. But when I put “http://….com/..vcf” in my browser on the Mac (Safari, Firefox, or Chrome), I get a text version only of the VCF. When I click to yours, whether from your site or the paste to the bottom “test only–do not click” portion of my site, my browser downloads your .pcf and offers to add you to my Address Book. Same problem on my Android browser on my phone, running 4.something ICS Android–your .vcf goes to my contacts app, while my .vcf goes to plain text of the .vcf or tries to open the .vcf as a photo.
My guess is that I can solve the desktop browser problem and the Android problem by doing the “mime-type is text/x-vcard” bit on my website, so that anytime a .vcf is accessed, it will be downloaded and offered to the contacts application.
I have no idea what I’m talking about, and I apologize if I’m wasting anyone’s time with this question. Regardless, I’m very impressed with how I can just click Jonas’s .vcard hyperlink or enter the .vcf’s URL in a browser and get what I need.
PS I’m using a domain forwarding service, so entering my domain name in a browser redirects one immediately to domainname.nfshost.com, and the vcard is stored on the public directory there. BTW I’ve tried using a URL with the original forwarded domain name and the actual one (with .nfshost.com).
Some one sent me a text say vcard2 when I click on it it tells me it is imported how do I reteive it
i wish to use v.c
ard on my phone.
Thanks for a marvelous posting! I really enjoyed reading it, you’re a great author. I will always bookmark your blog and may come back later in life. I want to encourage you to definitely continue your great posts, have a nice holiday weekend!
Simply want to say your article is as surprising. The clarity in your post is
just great and i can assume you are an expert on this subject.
Fine with your permission allow me to grab your RSS feed to keep
updated with forthcoming post. Thanks a million and please continue the enjoyable work.
My programmer is trying to persuade me to move to
.net from PHP. I have always disliked the idea because of the costs.
But he’s tryiong none the less. I’ve been using Movable-type on
a number of websites for about a year and am anxious about switching to another platform.
I have heard great things about blogengine.net.
Is there a way I can transfer all my wordpress posts into it?
Any help would be really appreciated!