使用此代码,我可以导出我设置的任何值,但除了我想要保存图像,生日,关系,协助,备注,标签,网站。
如何将此值设置为生成的vcf文件?
Person p = getPerson();
File vcfFile = new File(this.getExternalFilesDir(null), "generated.vcf");
FileWriter fw = new FileWriter(vcfFile);
fw.write("BEGIN:VCARD\r\n");
fw.write("VERSION:3.0\r\n");
fw.write("N:" + p.getSurname() + ";" + p.getFirstName() + "\r\n");
fw.write("FN:" + p.getFirstName() + " " + p.getSurname() + "\r\n");
fw.write("ORG:" + p.getCompanyName() + "\r\n");
fw.write("TITLE:" + p.getTitle() + "\r\n");
fw.write("TEL;TYPE=WORK,VOICE:" + p.getWorkPhone() + "\r\n");
fw.write("TEL;TYPE=HOME,VOICE:" + p.getHomePhone() + "\r\n");
fw.write("ADR;TYPE=WORK:;;" + p.getStreet() + ";" + p.getCity() + ";" + p.getState() + ";" + p.getPostcode() + ";" + p.getCountry() + "\r\n");
fw.write("EMAIL;TYPE=PREF,INTERNET:" + p.getEmailAddress() + "\r\n");
fw.write("END:VCARD\r\n");
fw.close();
Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(vcfFile), "text/x-vcard");
startActivity(i);
答案 0 :(得分:0)
这是古老的脚步,但我希望对您有帮助
我建议您阅读vCard的文档: https://tools.ietf.org/html/rfc2426
对于图片:
fw.write("PHOTO;VALUE=uri:www.abc.net/pub/logos/abccorp.jpg\r\n");
或
fw.write("PHOTO;ENCODING=b;TYPE=JPEG:MIICajCCAdOgAwIBAgICBEUwDQYJKoZIhvcN
AQEEBQAwdzELMAkGA1UEBhMCVVMxLDAqBgNVBAoTI05ldHNjYXBlIENvbW11bm
ljYXRpb25zIENvcnBvcmF0aW9uMRwwGgYDVQQLExNJbmZvcm1hdGlvbiBTeXN0\r\n");
//<...the remainder of "B" encoded binary data...>
生日:
fw.write("BDAY:1996-04-15\r\n");
对于关系
fw.write("ROLE:Programmer\r\n");
对于助手
fw.write("AGENT:BEGIN:VCARD\nFN:Susan Thomas\nTEL:+1-919-555-
1234\nEMAIL\;INTERNET:sthomas@host.com\nEND:VCARD\n\r\n");
笔记
fw.write("NOTE:This fax number is operational 0800 to 1715
EST\, Mon-Fri.\r\n");
对于标签:
fw.write("LABEL;TYPE=dom,home,postal,parcel:Mr.John Q. Public\, Esq.\n
Mail Drop: TNE QB\n123 Main Street\nAny Town\, CA 91921-1234
\nU.S.A.\r\n");
所有这些信息都是从https://tools.ietf.org/html/rfc2426
获得的