private List<Contract> readContacts() {
// android2.2
List<Contract> contracts = new ArrayList<Contract>();
Cursor cursor = getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (cursor.moveToNext()) {
HashMap<String, Object> map = new HashMap<String, Object>();
String phoneName = cursor.getString(cursor
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
map.put("ItemTitle", phoneName);// 电话姓名
String contactId = cursor.getString(cursor
.getColumnIndex(ContactsContract.Contacts._ID));
String hasPhone = cursor
.getString(cursor
.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (hasPhone.compareTo("1") == 0) {
Cursor phones = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID
+ " = " + contactId, null, null);
while (phones.moveToNext()) {
Contract cci = new Contract();
cci.name = phoneName;
String phoneNumber = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
String phoneTpye = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
map.put("ItemText", phoneNumber); // 多个号码如何处理
cci.number = phoneNumber;
// Log.d(TAG,"testNum="+ phoneNumber + "type:"+phoneTpye);
contracts.add(cci);
}
phones.close();
} else {
Contract cci = new Contract();
cci.name = phoneName;
cci.number = "";
contracts.add(cci);
}
}
return contracts;
}