更改自定义区域设置时,电话类型的标签将更改为适当的语言。有人知道如何获取手机类型的本地化标签吗?
我在应用程序中选择一个联系人来获取其电话号码,如果有多个号码,我使用 AlertDialog 让用户选择当前的号码。在此选择列表中,我想显示类型的标签,以便用户更容易选择。由于它们的标签位于 Android 系统中的某个位置,因此必须可以获得本地化标签。不幸的是,读取电话号码时,Phone.LABEL 为空。
When changing the custom locale the label of the phone types change to the appropriate language. Does anybody know how to get the localized label of the phone types?
I pick a contact in my app to get its phone number and if there is more then one number I use an AlertDialog to let the user select the currect one. In this pick list, I want to show the label of the type, so it's easier for the user to select. Since they labels are somewhere in the Android system, it must be possible to get the localized label. Unfortunately, the Phone.LABEL is null when reading the phone number.
发布评论
评论(4)
我知道这有点旧,但这:
对我有用
I know this is a bit old, but this:
worked for me
是的,您可以使用代码获取本地化的电话类型字符串:
但对于自定义电话类型,您应该考虑电话标签,而不仅仅是电话类型:
Yes, you can get localized phone type string with the code:
but for custom phone types you should cosider phone label, not only phone type:
Inferno 的答案是一个有效的答案,我很高兴找到这个答案,因为它与我正在寻找的答案相似。但是,如果您处理的是安装了 API Level 5 (Android 2.0) 或更高版本的手机,则存在一个小问题:
android.R.array.phoneTypes
仅返回手机类型列表从 API 级别 5 开始,ContactsContract
类取代Contacts
接口之前就存在。我验证了在运行这些 Android 版本的模拟器上创建新联系人时列出的标签(API级别):1.6 (4)、2.1 更新 1 (7) 和 2.2 (8)。打印出来时,
android.R.array.phoneTypes
包含以下有效的手机类型:家庭、手机、工作、工作传真、家庭传真、寻呼机、其他、自定义
这些是安装了 Android 2.0+ 的手机的有效手机类型,但同一数组中缺少这些类型:
回拨、汽车、公司主要、ISDN、主要、其他传真、无线电、电传、TTY TDD、工作移动、工作寻呼机、助理、彩信
不幸的是,我无法找到类似 android.R.array 的东西。 phoneTypes 将列出 Android 2.0+ 手机的所有有效手机类型。有人遇到过这样的吗?
参考
android.R.array.phoneTypes
定义:http://developer.android.com/reference/android/R.array.html#phoneTypes注意:我在单独的答案中发布了其他两个参考链接,因为目前我似乎无法在每篇文章中发布多个超链接。
Inferno's answer is a valid answer, and I was happy to find this answer because it was similar to what I was looking for. However, if you're dealing with phones installed with API Level 5 (Android 2.0) or newer, there is one small problem with this:
android.R.array.phoneTypes
only returns the list of phone types that were present prior to whenContactsContract
class replaced theContacts
interface as of API Level 5. I verified the labels listed when creating a new contact on emulators running these Android versions (API Levels): 1.6 (4), 2.1-update 1 (7), and 2.2 (8).When printed out,
android.R.array.phoneTypes
contains these valid phone types:Home, Mobile, Work, Work Fax, Home Fax, Pager, Other, Custom
These are the valid phone types, present for phones with Android 2.0+ installed, that are missing from that same Array:
Callback, Car, Company Main, ISDN, Main, Other Fax, Radio, Telex, TTY TDD, Work Mobile, Work Pager, Assistant, MMS
Unfortunately, I have not been able to find something like
android.R.array.phoneTypes
that'll list all of these valid phone types for phones Android 2.0+. Has anyone come across such yet?References
android.R.array.phoneTypes
defined: http://developer.android.com/reference/android/R.array.html#phoneTypesNote: I'm posting my other two reference links in separate answers, as I can't seem to post more than one hyperlink per post at this time.
我使用这段代码
没有找到任何地方来获取有效类型的实际计数,但是 http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Phone.html#getTypeLabelResource%28int%29 说它总是给出一个有效的 res,这样,您就可以迭代,直到它开始给出重复的值...20 后给我自定义的 res。
i am using this piece of code
didn't found any place to get the actual count of valid types but http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Phone.html#getTypeLabelResource%28int%29 says it will always give a valid res so, you can iterate until it start giving repeated values... to me after 20 gives me the custom res.