我需要亲自联系。在android 4.0及更高版本中,我们有一个数据联系人。我已经尝试了ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME
,但是在没有数据联系的情况下我收到了所有联系人。知道如何获得它吗?
这是我的代码:
public String getMyName(ContentResolver resolver){
Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String[] columns = new String[] {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER};
Cursor people = resolver.query(uri, columns, null, null, null);
try {
int nameIndex = people.getColumnIndex(columns[0]);
int numberIndex = people.getColumnIndex(columns[1]);
people.moveToFirst();
do{
Log.d("Contact result", "Contact name: " + people.getString(nameIndex) + " contact phone: " + people.getString(numberIndex));
} while (people.moveToNext());
}catch (NullPointerException e){
Log.d("Exception", "Null pointer on get personal data");
}
return null;
}