2012-11-02 49 views
0

這是我的代碼,用於將聯繫人導出到SDcard上的VCF文件。但我無法在SDCard上找到vcf。 幫我看看。在此先感謝在SDCard Android仿真器上找不到vcf文件

代碼獲取VCF文件:

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(); 
    } 

} 
} 

清單 //在未經許可的

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

回答

0

嘗試:

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

我剛試過,我不工作。 –

+0

你可以驗證(通過調試),「路徑」指向你想要它?另外,你在哪裏調用'mFileOutputStream.close()'? –

+0

我開始在android中,你能告訴我如何通過logcat或調試來驗證「路徑」嗎? –

相關問題