【发布时间】:2016-02-02 11:07:48
【问题描述】:
我需要获取我的个人联系方式。在 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;
}
【问题讨论】: