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.
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, "");
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With