`
dengzhangtao
  • 浏览: 668156 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

android导出通讯录,通话记录,短信

 
阅读更多
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
int index = cur.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY);
FileOutputStream fout;
try {
String sdpath = Environment.getExternalStorageDirectory().getAbsolutePath();
String path = sdpath+"/tt.vcf";
File f = new File(path);
f.createNewFile();
fout = new FileOutputStream(path);
byte[] data = new byte[1024 * 1];
while(cur.moveToNext()){
String lookupKey = cur.getString(index);
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);
AssetFileDescriptor fd = this.getContentResolver().openAssetFileDescriptor(uri, "r");
FileInputStream fin = fd.createInputStream();
int len = -1;
while((len = fin.read(data)) != -1){
fout.write(data, 0, len);
}
fin.close();
}
fout.close();
} catch (Exception e) {
debug(e.toString());
}
上面实现了通讯录的导出备份。
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics