我从手机上获取了姓名,电话号码和电话类型的联系人列表。电话类型可能是1(家庭),2(移动)等...当电话类型是自定义的(例如," CustomType")时,电话类型的值返回0.那么,我怎么能获取字符串" CustomType",当电话类型为0?
时答案 0 :(得分:2)
也许这段代码会很有用:
String contactType = "";
final int labelType = cur.getInt(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
if(labelType == ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM)
{
contactType = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.LABEL));
}
else
{
//Easy case
}
cur 是执行查询....getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI...