Search code examples
androidlocalizationinternationalizationunits-of-measurement

Using locale settings to detect wheter to use imperial units


I'm working on an app that wants to display lengths either in centimeters (cm) or in inches("). Is there a way to select the right unit from the locale? In any event I'm also going to put in an option so that the user can to override the locale setting.

USA, Liberia, and Burma should use imperial units and the rest of the world normal units. One way is to put in this logic in my own classes, but I would prefer using any built in logic if available. Any pointers?


Solution

  • LocaleData.getMeasurementSystem is available from API level 28 and beyond. It returns the information you are looking for.