I am trying to send a VCard from a String or file via Intents choosing the app, for example Whatsapp. Do you have any ideas?
Thanks
Edit:
I have tried this code. Also with set type text/plain. The vcard variable is a String with a VCard.
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setType("text/x-vcard");
intent.putExtra(android.content.Intent.EXTRA_STREAM, vcard);
intent.setPackage(packageName);
If I send this to Whatsapp I got to send the vcard like a string but not recognize like a card
Try using EXTRA_TEXT
instead of EXTRA_STREAM
, as EXTRA_STREAM
is supposed to point to a file.
Also, please delete the setPackage()
call. You are not more important than your user. Your user, therefore, gets to control what app they share their vCard with, not you.
Beyond that, please contact Whatsapp for assistance with their app. Particularly given your setPackage()
call, it is entirely possible that Whatsapp simply does not support vCard via ACTION_SEND
.
Try this:
intentShareFile.setDataAndType(Uri.fromFile(vcfFile),"text/x-vcard");
intentShareFile.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+vcfFile));
instead of:
intent.setType("text/x-vcard");
来源:https://stackoverflow.com/questions/14942434/send-vcard-file-string-via-whatsapp-or-mail-programmatically