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());
}
上面实现了通讯录的导出备份。