且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

找不到SD卡Android模拟器的vcf文件

更新时间:2023-11-20 20:58:52

尝试:

 字符串路径= Environment.getExternalStorageDirectory()getAbsolutePath()+文件分割符+ vfile。

Here is my code to export contacts to VCF file on SDcard. But i can't find vcf on SDCard. Help me find that. Thanks in advance

Code to get VCF file:

public static void getVCF() 

{

 final String vfile = "POContactsRestore.vcf";

 Cursor phones = mContext.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null, null, null);

 phones.moveToFirst();
   for(int i =0;i<phones.getCount();i++)
   {
      String lookupKey =  phones.getString(phones.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
     Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);

    AssetFileDescriptor fd;
     try 
     {
         fd = mContext.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 mFileOutputStream = new FileOutputStream(path, true);
                    mFileOutputStream.write(VCard.toString().getBytes());           
         phones.moveToNext();                           
         Log.d("Vcard",  VCard);
     } 
     catch (Exception e1) 
     {
          // TODO Auto-generated catch block
          e1.printStackTrace();
     }

 }
}

Manifest // permisson

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

try:

    String path = Environment.getExternalStorageDirectory().getAbsolutePath() + file.separator + vfile;