android导出通讯录,通话记录,短信
16lz
2022-03-15
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());
}
上面实现了通讯录的导出备份。
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());
}
上面实现了通讯录的导出备份。
更多相关文章
- android 读取通讯录
- Android(安卓)导出数据库到Excel表格功能
- android通讯录实例(二)
- [通讯录] android通讯录数据库表解析和添加,访问通讯录
- android手机通讯录备份还原代码
- Android打开通讯录并获取数据
- gif文件导出png
- [Android] 备份手机上的超级终端、VIM
- Android(安卓)- 利用Android(安卓)studio + Android(安卓)Killer