我正在使用下面的代码从电话簿中获取联系人姓名
Uri contactUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
Cursor phones = getContentResolver().query(contactUri,null,null,null,null);
while (phones.moveToNext())
{
String name = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
if (name != null)
{
names += name + ",";
}
}
phones.close();
我注意到当有一个没有名字保存的联系人时,上面的代码将返回电话号码作为联系人姓名。我知道这就是 android 的工作方式,以防联系人在没有名字的情况下保存。但是我必须阻止这种行为并强制它返回 null 或空字符串,以防没有“Display_Name”..
可能吗?