I am implementing a vcard where users can add to contact with all the information populated. I am currently using this package: jeroendesloovere/card (https://github.com/jeroendesloovere/vcard).
When testing my implementation, it works perfectly on IOS device as it immediately opens the preview window for adding a contact, but for android devices it does not work. It just navigates to another url browser saying this site cannot be reached. I am not sure if this is android behavior where it could not detect a vcf file. I am not sure if there is a workaround to make it automatically open the contact preview on android like how it be on IOS.
my code:
public function download($vcard_data)
{
$vcard = new VCard();
$lastname = '';
$firstname = '';
$additional = '';
$prefix = '';
$suffix = '';
foreach ($vcard_data->phoneNumbers as $phoneNumber) {
$type = "TYPE={$phoneNumber->type}";
$vcard->addPhoneNumber($phoneNumber->phoneNumber, $type);
}
foreach ($vcard_data->emails as $email) {
$type = "TYPE={$email->type}";
$vcard->addEmail($email->address, $type);
}
foreach ($vcard_data->socialMedias as $socialMedia) {
$type = "TYPE={$socialMedia->type}";
$vcard->addURL($socialMedia->link, $type);
}
$vcard->addName('', $vcard_data->name);
$vcard->addCompany($vcard_data->companyName);
$vcard->addJobtitle($vcard_data->designation);
$vcard->addURL($vcard_data->companyWebsite, 'WORK');
$vcard->addPhoto($vcard_data->photoUrl);
//return $vcard->getOutput();
return $vcard->download();
}
}
I tried adding header to specify the content disposition as attachment like :
....
$vcardOutput = $vcard->getOutput();
// Set headers for downloading vCard
header('Content-Type: text/vcard');
header('Content-Disposition: attachment; filename="contact.vcf"');
echo $vcardOutput;
exit;
}
Unfortunately it does not work as well. I just want it to trigger contact app to open and preview like IOS but just couldn’t figure out a solution.
Has anyone encounter this issue and know how to fix it?