聯絡人名稱 與 電話
名稱
static final String[] CONTACTS_PROJECTION = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.PHOTO_ID,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.HAS_PHONE_NUMBER,
};
Cursor cur = contentResolver.query(
ContactsContract.Contacts.CONTENT_URI, new String[] {CONTACTS_PROJECTION, null, null, ContactsContract.Contacts._ID);
try {
if (cur.moveToFirst()) {
int idCol = cur.getColumnIndex(ContactsContract.Contacts._ID);
int photoCol = cur.getColumnIndex(ContactsContract.Contacts.PHOTO_ID);
int displayNameCol = cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
int hasPhoneNumberCol = cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER);
do {
long id = cur.getLong(idCol);
long photoId = cur.getLong(photoCol);
String name = cur.getString(displayNameCol);
boolean hasPhoneNumber = cur.getInt(hasPhoneNumberCol) != 0;
// contactsMap.put(id, contact);
} while (cur.moveToNext());
}
} finally {
cur.close();
}
電話
static final String[] COMMONDATAKIND_PHONE_PROJECTION = new String[]{
CommonDataKinds.Phone.CONTACT_ID,
CommonDataKinds.Phone.TYPE,
CommonDataKinds.Phone.NUMBER,
CommonDataKinds.Phone.IS_PRIMARY,
};
Cursor cur = contentResolver.query(CommonDataKinds.Phone.CONTENT_URI,
COMMONDATAKIND_PHONE_PROJECTION, null, null,
CommonDataKinds.Phone.CONTACT_ID);
try {
if (cur.moveToFirst()) {
int idCol = cur.getColumnIndex(CommonDataKinds.Phone.CONTACT_ID);
int typeCol = cur.getColumnIndex(CommonDataKinds.Phone.TYPE);
int numberCol = cur.getColumnIndex(CommonDataKinds.Phone.NUMBER);
int isPrimaryCol = cur .getColumnIndex(CommonDataKinds.Phone.IS_PRIMARY);
do {
long id = cur.getLong(idCol);
int type = cur.getInt(typeCol);
String number = cur.getString(numberCol);
boolean primary = cur.getInt(isPrimaryCol) != 0;
if (number != null) {
;
}
} while (cur.moveToNext());
}
} finally {
cur.close();
}
浙公网安备 33010602011771号