How to get a localized phone type shortcut?

When changing the user locale, the label of the phone types changes to the corresponding language. Does anyone know how to get a localized phone type shortcut?

I select a contact in my application to get its phone number, and if there is more than one number, I use AlertDialog so that the user can select the correct one. In this selection list, I want to show the type label, so it’s easier for the user to select. Since these shortcuts are located somewhere on the Android system, it should be possible to get a localized shortcut. Unfortunately, Phone.LABEL is NULL when reading a phone number.

+6
android phone-number
source share
4 answers

I know this is a little outdated, but this:

Phone.getTypeLabel(this.getResources(), cursor.getInt(typeIdx), ""); 

worked for me

+17
source share

Inferno's answer is the correct answer, and I was happy to find this answer because it looked like what I was looking for. However, if you are dealing with phones installed with API level 5 (Android 2.0) or later, there is one small problem with this: android.R.array.phoneTypes returns only a list of phone types that were present before the class was replaced ContactsContract interface by Level 5 API. I checked the labels listed when creating a new contact on emulators running these versions of Android (API levels): 1.6 (4), 2.1-update 1 (7) and 2.2 (8).

When printed, android.R.array.phoneTypes contains these valid phone types:
Home, Mobile, Work, Work Fax, Home Fax, Pager, Other, Custom

These are valid phone types present for phones with Android 2.0+ installed that are not in the same array:
Callback, Car, Company Main, ISDN, Main, Other Fax, Radio, Telex, TTY TDD, Work Mobile, Work Pager, Assistant, MMS

Unfortunately, I could not find something like android.R.array.phoneTypes , which lists all these valid phone types for Android 2.0+ phones. Has anyone else come across this?

References

android.R.array.phoneTypes : http://developer.android.com/reference/android/R.array.html#phoneTypes

Note. I am posting two other link links in separate answers, since I cannot post more than one hyperlink to the message at this time.

+1
source share

I use this piece of code

  public void getPhoneType(){ int res; for(int i=0;i<=20;i++){ res = ContactsContract.CommonDataKinds.Phone.getTypeLabelResource(i); Log.d(TAG,"i: "+ i +" type: " + context.getString(res)); } } 

there was no place to get the actual number of valid types, but http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Phone.html#getTypeLabelResource%28int%29 says it will always give valid res so, you can iterate until it starts giving duplicate values ​​... after 20 it gives me custom values.

+1
source share

Yes, you can get a localized string like phone with code:

 int phoneNumberType = (int)pCur.getInt(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE)); ContactsContract.CommonDataKinds.Phone.getTypeLabel(context.getResources(), phoneNumberType , "") 

but for custom phone types you should use a phone tag, not just a phone type:

 String phoneLabel = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.LABEL)); 
+1
source share

All Articles