找不到SD卡Android模拟器的vcf文件 [英] Can't find vcf file on SDCard Android Emulator
本文介绍了找不到SD卡Android模拟器的vcf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的code出口SD卡上的联系人VCF文件。但我找不到SD卡VCF。
帮我看看那个。在此先感谢
code得到VCF文件:
公共静态无效getVCF(){ 最后弦乐vfile =POContactsRestore.vcf; 。光标手机= mContext.getContentResolver()查询(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,NULL,NULL,NULL,NULL); phones.moveToFirst();
的for(int i = 0; I< phones.getCount();我++)
{
串lookupKey = phones.getString(phones.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
URI URI = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI,lookupKey); AssetFileDescriptor的fd;
尝试
{
FD = mContext.getContentResolver()openAssetFileDescriptor(URI,R)。
FIS的FileInputStream = fd.createInputStream();
字节[] buf中=新的字节[(INT)fd.getDeclaredLength()];
fis.read(BUF);
字符串电子名片=新的String(BUF);
字符串路径= Environment.getExternalStorageDirectory()的toString()+文件分割符+ vfile。
FileOutputStream中mFileOutputStream =新的FileOutputStream(路径,真实);
mFileOutputStream.write(VCard.toString()的getBytes());
phones.moveToNext();
Log.d(电子名片,电子名片);
}
赶上(例外E1)
{
// TODO自动生成catch块
e1.printStackTrace();
} }
}
清单
//在未经许可
<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAGE/>
解决方案
尝试:
字符串路径= 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;
这篇关于找不到SD卡Android模拟器的vcf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文