Я использовал для одного из своих проектов следующее решение.Это сработало отлично.В качестве библиотеки vCard я использовал cardme v.0.26, которая также поддерживает vcard версии 3.0.
примечание: имя файла хранится в res / values / strings.xml ...
/*
* Create file. This file has to be readable, otherwise the contact
* application cannot access the file via URI to read the vcard
* string.
*/
// эта переменная содержит вашу vCard в виде строки String vcardString;
FileOutputStream fOut = openFileOutput(
getResources().getText(R.string.app_vcard_file_name)
.toString(), MODE_WORLD_READABLE);
osw = new OutputStreamWriter(fOut);
// write vcard string to file
osw.write(vcardString);
// ensures that all buffered bytes are written
osw.flush();
} catch (NotFoundException e) {
// ..
} catch (IOException e) {
// ...
} finally {
if (osw != null) {
try {
osw.close();
} catch (IOException e) {
// ...
}
}
}
// let the os handle the import of the vcard to the Contacts
// application
Intent i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(Uri.parse("file://"
+ getFileStreamPath(
getResources().getText(R.string.app_vcard_file_name)
.toString()).getAbsolutePath()), "text/x-vcard");
startActivity(i);