我想要获得GIVEN_NAME和FAMILY_NAME,但有时我会收到不正确的数据。我将在下面给出日志。
ContentResolver cr = context.getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
getNameStructure(cr, id);
private void getNameStructure(ContentResolver cr, String id) {
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, null, ContactsContract.Data.RAW_CONTACT_ID + "= ?", new String[]{id}, null);
int indexGivenName = cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME);
int indexFamilyName = cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME);
int indexDisplayName = cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME);
if (cursor.moveToNext()) {
String given = cursor.getString(indexGivenName);
String family = cursor.getString(indexFamilyName);
String display = cursor.getString(indexDisplayName);
Log.d("Log", " given " + given + " family " + family + " display " + display);
}
cursor.close();
}
是日志示例:
given Vg family null display Vg //correct
given Xcy family null display Xcy //correct
given 2 family null display 536-55-55 //no corrent, i don`t know what is in given and family, but display is phone, but must be name "Note test con111"