现在我一直在做同样的事情后,确保您的查询是正确的(我查询ContactsContract.CommonDataKinds.Phone.CONTENT_URI )(确保你的投影是正确的,等等)你可以做下面的事情,我想你面临的困难是拿起一个预设标签与自定义标签。预设标签在TYPE列中表示为整数,而如果TYPE == TYPE_CUSTOM,则LABEL字段将包含您要查找的数据。
从TYPE中的数字移动到字符串是使用提供的方法。虽然我认为这是处理的,但我不确定本地化。
Cursor curse = mContext.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, new String[]{ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.LABEL},
ContactsContract.CommonDataKinds.Phone.NUMBER + " = ?", new String[]{numnum}, null);
int colIndex = curse.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE);
int lblIndex = curse.getColumnIndex(ContactsContract.CommonDataKinds.Phone.LABEL);
ArrayList<String> numbers = new ArrayList<String>();
String cur = "";
while(curse.moveToNext())
{
int labelType = curse.getInt(colIndex);
if(labelType == ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM)
{
cur = curse.getString(lblIndex);
}
else
{
CharSequence seq = ContactsContract.CommonDataKinds.Phone.getTypeLabel(mContext.getResources(), labelType, "Mobile");
cur = seq.toString();
}
numbers.add(cur);
}
curse.close();
在这个片段中,你会用装有用于此电话号码的标签的字符串的ArrayList最终结束。请注意电话号码需要非常精确的匹配,所以444-4444不会与4444444匹配,反之亦然。
个人而言,我还没有时间去尝试将“移动”或“”放在getTypeLabel中的最后一个变量之间有什么区别,尽管它看起来没有什么区别。
希望这个答案还不算晚。