I have an application where part of the functionality is user will generate a QR code and other users can scan and get contact details and add to their contact directly.
So i am encoding vCard details in below format:
String str =
"BEGIN:VCARD\n" +
"VERSION:3.0\r\n" +
"N:" + userDetailsModel.getLastName() + ";" + userDetailsModel.getFirstName() + ";;Mr;\r\n" +
"FN:" + "Mr." + userDetailsModel.getFirstName() + " " + userDetailsModel.getLastName() + "\r\n" +
"ORG:" + userDetailsModel.getCompany() + "\r\n" +
"TITLE:" + userDetailsModel.getDesignation() + "\r\n" +
"EMAIL:" + userDetailsModel.getEmail() + "\r\n" +
"TEL;CELL:" + userDetailsModel.getPhone() + "\r\n" +
"END:VCARD\r\n";
Then upon receiving this string after being scanned , i am writing this to a file and then starting an intent action with the file to open and add to contact. Below is my code:
VCard vCard = Ezvcard.parse(qrResultDataString).first();
writeToFile(qrResultDataString);
Intent intent = new Intent(Intent.ACTION_VIEW);
File path = new File(getApplicationContext().getExternalFilesDir(null), "contactFile.vcf");
try {
VCardWriter writer = new VCardWriter(path, VCardVersion.V3_0);
writer.write(vCard);
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
Uri uri = Uri.parse(path.getPath());
intent.setDataAndType(uri, "text/x-vcard"); //storage path is path of your vcf file and vFile is name of that file.
startActivity(intent);
Ignore the EZvcard part.
As a result i am getting option to add to contact and when i select any contact app a toast is showing with text "couldn't import vCard". I am not getting any error message in logcat either. Please help.