0
我正在使用以下代碼爲單個聯繫人創建vcf文件。我想要的是,當我點擊特定聯繫人時,它會爲該聯繫人創建一個vcf文件。 這裏是我使用的代碼:如何爲所選聯繫人創建.vcf文件
String vfile = "test1.vcf";
cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
cursor.moveToFirst();
String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);
AssetFileDescriptor fd;
try {
fd = getContentResolver().openAssetFileDescriptor(uri, "r");
FileInputStream fis = fd.createInputStream();
byte[] buf = new byte[(int) fd.getDeclaredLength()];
fis.read(buf);
String VCard = new String(buf);
String path = Environment.getExternalStorageDirectory().toString() + File.separator + vfile;
FileOutputStream out = new FileOutputStream(path);
out.write(VCard.toString().getBytes());
Log.d("Vcard", VCard);
} catch (Exception e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
任何幫助,將不勝感激。
幫我 「智能灰」 http://stackoverflow.com/questions/13198933/cant-find-vcf-file-on-sdcard-android-emulator/13199144#comment17969669_13199144 感謝提前 – 2012-11-02 16:53:41