【问题标题】:Can't find vcf file on SDCard Android Emulator在 SDCard Android 模拟器上找不到 vcf 文件
【发布时间】:2012-11-02 16:05:08
【问题描述】:

这是我将联系人导出到 SD 卡上的 VCF 文件的代码。但我在 SDCard 上找不到 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"/>

【问题讨论】:

    标签: android vcf-vcard


    【解决方案1】:

    尝试:

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

    【讨论】:

    • 你能验证(通过调试)“路径”指向你想要的地方吗?另外,你在哪里打电话给mFileOutputStream.close()
    • 我开始使用 android,你能告诉我如何通过 logcat 或调试来验证“路径”吗?
    • 我假设您使用的是 Eclipse。如果是这样,您可以右键单击一行的开头并“设置断点”。要在调试模式下启动应用程序,只需按 F11。调试器应该在断点处停止。
    • 如果对您有帮助,请“投票”我的回答。祝你未来的项目好运!
    • 谁能帮我解决这个问题。提前致谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-17
    • 1970-01-01
    • 2011-05-21
    • 1970-01-01
    • 2011-09-28
    • 1970-01-01
    相关资源
    最近更新 更多