Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translating android phone number label id to string

Hi Im writing a small android app that is closely working whit phone labels but I don't understand how I'm suposed to translate the uri values described in the Documentation.

What i want to do is to translate TYPE_HOME To Home and so on. My current solution is to have a list of all translated string but it has presented a lot of problem with languish. But i want to be able to do it like the addresbook and other apps doses it.

like image 272
KilledKenny Avatar asked Apr 10 '11 10:04

KilledKenny


3 Answers

Android has a built in method to do this already ...

import android.provider.ContactsContract.CommonDataKinds.Phone;
String s = (String) Phone.getTypeLabel(context.getResources(), Phone.TYPE_HOME, "");
like image 82
ekawas Avatar answered Oct 31 '22 16:10

ekawas


Looking at the source code for ContactsListActivity, it appears that the Android developers just mapped values like Phone.TYPE_MOBILE to values they defined in strings.xml, just for that app, indicating there is no universal system label to easily lookup (for example, as one might use @android:drawable to use system graphics, which is not a recommended practice, as the images change between platforms).

like image 40
Thane Anthem Avatar answered Oct 31 '22 17:10

Thane Anthem


As far as I know there're no resources for labels. You can only have all strings as resources in your own app and convert default types to these strings.

UPDATE: There're a lot of solutions for converting label type to string. For example, you can define string-array resource:

<string-array name="labels">
    <item>@string/phone</item>
    <item>@string/mobile</item>
    <item>@string/work</item>
</string-array>

Then you should define these string for all languages you support. You'll be able to convert label code to string after loading this array with getResources().getTextArray(R.array.labels). Also you have to deal with custom labels.

That's a possible solution but in fact everything depends on your app's architecture.

like image 31
Michael Avatar answered Oct 31 '22 16:10

Michael