I want to save a contact data which is in VCard
format in user's contacts via sending intent. Is there any way to do it?
NOTE: I don't want to save VCard
data in a .vcf
file and then give it's uri
to intent
like the code below.
String scanned = "..." // contact in VCard format
Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_VIEW);
File vcfFile = new File(getCacheDir(), "tmp.vcf");
try {
FileOutputStream fos = new FileOutputStream(vcfFile);
OutputStreamWriter osw = new OutputStreamWriter(fos);
osw.write(scanned);
osw.close();
fos.close();
i.setDataAndType(Uri.fromFile(vcfFile), "text/vcard");
startActivity(i);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
If the contact is indeed in the contacts database, you could look at the android contacts app's code, to see how to share a vcard out of it (found from here, inside a file called "QuickContactActivity.java" ) :