假设我有一个编辑文本和一个按钮。在编辑文本中,您可以输入一个数字,然后当您点击该按钮时,它将显示联系信息或返回该联系人的姓名。从号码获取联系人姓名
我已经尝试了各种方法提供没有运气。我成功地获得了最远的一个是以下...但我没有运气返回这个名字。
Cursor phoneCursor = null;
contactList = new HashMap<String,String>();
try{
Uri uContactsUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String strProjection = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME;
phoneCursor = getContentResolver().query(uContactsUri, null, null, null, strProjection);
phoneCursor.moveToFirst();
String name = "";
String phoneNumber = "";
int nameColumn = phoneCursor.getColumnIndex(Phone.DISPLAY_NAME);
int phoneColumn = phoneCursor.getColumnIndex(Phone.NUMBER);
phoneCursor.moveToNext();
}
}
catch(Exception e){
Log.e("[SmsMain] getContactData", e.toString());
}
finally{
if(phoneCursor != null){
phoneCursor.close();
phoneCursor = null;
}
}
}