public static String getContactNameByAddr(Context context,
String phoneNumber) {
Uri personUri = Uri.withAppendedPath(
ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(phoneNumber));
Cursor cur = context.getContentResolver().query(personUri,
new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null);
if (cur.moveToFirst()) {
int nameIdx = cur.getColumnIndex(PhoneLookup.DISPLAY_NAME);
String name = cur.getString(nameIdx);
cur.close();
return name;
}
return phoneNumber;
}
解释:该函数仅需要2个参数:context 和 手机号码