我正在关闭存储在联系人列表中的所有联系人.vcf文件,并将其保存在SD卡中,但所有.vcf文件都存储在我的SD卡中,我想在侧面的SD卡中创建一个文件夹并保存所有的.vcf文件在它里面......最后得到文件夹的路径,并能够将其邮寄到电子邮件ID中。如果我的设备的联系人列表中有数千个联系人,如何创建一个文件夹来保存所有.vcf文件。< / p>
我的代码用于制作.vcf并将其保存在sdcard中。请修改相同或提供一些新想法...
private void getVcardString() {
int j=0;
// TODO Auto-generated method stub
vCard = new ArrayList<String>();
cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if(cursor!=null&&cursor.getCount()>0)
{
cursor.moveToFirst();
for(int i =0;i<cursor.getCount();i++)
{
get(cursor);
Log.d("TAG", "Contact "+(i+1)+"VcF String is"+vCard.get(i));
publishProgress(Integer.toString(j));
j++;
cursor.moveToNext();
}
csv_status = true;
}
else
{
Log.d("TAG", "No Contacts in Your Phone");
}
}
public void get(Cursor cursor)
{
vfile = "Contacts" + "_" + System.currentTimeMillis()+".vcf";
//String vfile = "Contacts"+".vcf";
//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 = CsvSender.this.getContentResolver().openAssetFileDescriptor(uri, "r");
FileInputStream fis = fd.createInputStream();
byte[] buf = new byte[(int) fd.getDeclaredLength()];
fis.read(buf);
String vcardstring= new String(buf);
vCard.add(vcardstring);
String storage_path = Environment.getExternalStorageDirectory().toString() + File.separator + vfile;
FileOutputStream mFileOutputStream = new FileOutputStream(storage_path, false);
mFileOutputStream.write(vcardstring.toString().getBytes());
}catch (Exception e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
}