Check out googlei18n / libaddressinput: Googles mail address library including Android and Chromium . There are two modules in the project: android and: general. You only need: general to format the address to display the locale.
import android.location.Address; import android.support.annotation.NonNull; import android.text.TextUtils; import com.google.i18n.addressinput.common.AddressData; import com.google.i18n.addressinput.common.FormOptions; import com.google.i18n.addressinput.common.FormatInterpreter; ... public static String getFormattedAddress(@NonNull final Address address, @NonNull final String regionCode) { final FormatInterpreter formatInterpreter = new FormatInterpreter(new FormOptions().createSnapshot()); final AddressData addressData = (new AddressData.Builder() .setAddress(address.getThoroughfare()) .setLocality(address.getLocality()) .setAdminArea(address.getAdminArea()) .setPostalCode(address.getPostalCode()) .setCountry(regionCode)
NOTE. regionCode must be a valid iso2 country code because the format interpreter format is used here. (See RegionDataConstants for a list of formats if you're interested.)
Sets the 2-letter region code of the CLDR address; see AddressData # getPostalCountry (). Unlike other values passed to builder, the region code can never be null.
Example: US
801 CHESTNUT ST
ST. LOUIS, MO 63101
Example: JP
〒1600023
Nishishinjuku
3-2-11 NISHISHINJUKU SHINJUKU-KU TOKYO
source share