Send VCard file/string via Whatsapp or mail programmatically

喜欢而已 提交于 2019-12-10 11:09:08

问题


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


回答1:


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.




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!