ContactScontract.CommonDatakinds.Phone.GetTypelabel返回摩托罗拉设备上



我正在使用contactscontract.commondatakinds.phone.getTypelabel获取用户的手机类型的字符串(1-> home,2->移动,3->工作等(。在大多数设备上,一切似乎都可以正常工作,但是在摩托罗拉设备上,返回的字符串是我什至无法在这里输入的一些奇怪的char(看起来像韩语/日语/泰语(。这些设备的位置是英语,用户也无法理解那些奇怪的字符串。

我的代码很直接:

return ContactsContract.CommonDataKinds.Phone.getTypeLabel(context.getResources(), type, "").toString();

获得联系人的预定标签非常直接,但是,如果用户设置了自定义标签,则它不是直接的,您可以尝试使用Follwing来获得正确的标签:

int type = cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
            String label = context.getResources().getString(ContactsContract.CommonDataKinds.Phone.getTypeLabelResource(type));
            if (label.equalsIgnoreCase("Custom")){
                label = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.LABEL));
            }

您现在可以直接使用标签字符串。

以这种方式,在typeName中,您将获得标准或自定义标签。(crPhones是迭代与单个联系人相关的数字的光标(:

String label = crPhones.getString(crPhones.
        getColumnIndex(ContactsContract.CommonDataKinds.Phone.LABEL));
int type = crPhones.getInt(crPhones.
        getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
String typeName = ContactsContract.CommonDataKinds.Phone.
        getTypeLabel(context.getResources(), type, label).toString();

最新更新