当我简单查询我的联系人时,列表中显示的所有联系人还包括 facebook 联系人和 Gmail 联系人,但是当我使用此代码时,一些 vcard 是空白的......
String VCard = "";
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null, null, null);
phones.moveToFirst();
pDialog.setMax(phones.getCount());
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 = getContentResolver().openAssetFileDescriptor(uri, "r");
FileInputStream fis = fd.createInputStream();
byte[] buf = new byte[(int) fd.getDeclaredLength()];
fis.read(buf);
VCard += new String(buf);
String y =String.valueOf(i);
publishProgress(y);
phones.moveToNext();
Log.d("Vcard", VCard);
}
catch (Exception e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
try {
FileOutputStream mFileOutputStream = new FileOutputStream(file, false);
mFileOutputStream.write(VCard.toString().getBytes());
mFileOutputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}