Hi! I’d like to know if I can add a vcard (.vcf file) to a android phone by using the web share api?
Have you tried calling [canShare](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/canShare)
to see what it returns?
Yes I did. My example works on ios, but not on android.
Here is my code.
export function shareVCard() {
fetch(“sample.vcf”)
.then(function(response) {
return response.text()
})
.then(function(text) {
var file = new File([text], "sample.vcf", {type: 'text/vcard'}); //text/x-vcard
var filesArray = [file];
var shareData = { files: filesArray };
if (navigator.canShare && navigator.canShare(shareData)) {
// Adding title afterwards as navigator.canShare just
// takes files as input
shareData.title = "Sample";
navigator.share(shareData)
.then(() => console.log('Share was successful.'))
.catch((error) => console.log('Sharing failed', error));
} else {
console.log("Your system doesn't support sharing files.");
}
});
}
Do you get the above when running on Android? I have to admit I am not very familiar with the Web Share API. If you see the above on Android then I guess it is not yet supported. I looks like Chrome on Android does support it but not the Android web view: Web Share API - Web APIs | MDN
Is your web application perhaps run inside a web view?
I’m running it on the android chrome browser, it supports the web share api. When I share a .txt file or an image it works, but not when it comes to a .vcf file, the issue might be with the .vcf. When I share the .vcf file on ios chrome it works.
Ha! That is interesting. I wonder, perhaps it is worth raising an issue on the BCD repo? https://github.com/mdn/browser-compat-data/issues/new/choose