编辑
我正在将我的应用移植到阿拉伯语区域设置.我有一些带有以下参数的getString():
getString(R.string.distance, distance)
Run Code Online (Sandbox Code Playgroud)
哪里 <string name="distance">%1d km</string>
要求是在阿拉伯语中我应该这样表达:"2.3كم".
如果我设置为沙特阿拉伯(country ="sa")或阿联酋(country ="ae")的区域设置,则数字以东方阿拉伯语显示,但我的客户希望使用西方阿拉伯语.
这里的解决方案是使用埃及作为当地的国家,但这对我来说是不可能的.
我试过了:
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void setAppContextLocale(Locale savedLocale) {
Locale.Builder builder = new Locale.Builder();
builder.setLocale(savedLocale).setExtension(Locale.UNICODE_LOCALE_EXTENSION, "nu-latn");
Locale locale = builder.build();
Configuration config = new Configuration();
config.locale = locale;
config.setLayoutDirection(new Locale(savedLocale.getLanguage()));
mAppContext.getResources().updateConfiguration(config, mContext.getResources().getDisplayMetrics());
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用"en_us","en_gb"等区域获取当前设备区域设置.
我正在打电话Locale.getDefault().getLanguage(),它只返回两个字母代码en.
我想在不使用SIM卡的情况下获取设备国家/地区代码。
例如,如果国家/地区:斯里兰卡国家/地区代码:LK
我的最终目标是获取调用代码(斯里兰卡为+94)
我尝试过
TelephonyManager tm = (TelephonyManager)this.getSystemService(getApplicationContext().TELEPHONY_SERVICE);
String countryCodeValue = tm.getNetworkCountryIso();
Run Code Online (Sandbox Code Playgroud)
但这返回空字符串
我在我的应用程序中添加了对每种应用程序语言的支持,即 android 13 功能,现在它是英语和俄语。我可以从设置更改应用程序语言,而无需更改设备语言。现在出于分析目的,我需要了解应用程序语言和设备语言。但如果我的设备是英语且应用程序是俄语,我总是收到俄语 -
Resources.getSystem().configuration.locales.get(0).language - ru
context.resources.configuration.locales[0].language - ru
Locale.getDefault().language - ru
Run Code Online (Sandbox Code Playgroud)
我希望收到来自
Resources.getSystem().configuration.locales.get(0).language
Run Code Online (Sandbox Code Playgroud)
和 茹从
context.resources.configuration.locales[0].language
Run Code Online (Sandbox Code Playgroud)
我会很高兴得到任何帮助