android根据联系人电话号码查询联系人姓名
public static String getDisplayNameByTelNum(String num,Context context)
{
Cursor cursorOriginal =
context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
new String[] {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME},
ContactsContract.CommonDataKinds.Phone.NUMBER + "='"+num+"'",null,null);
if(null!=cursorOriginal)
{
if(cursorOriginal.getCount()>1)
{
return null;
}else{
if(cursorOriginal.moveToFirst())
{
return cursorOriginal.getString(cursorOriginal.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
}else
{
return null;
}
}
}else
{
return null;
}
}