更改设备系统区域设置不适用于印地语和孟加拉语以外的印度语言
Changing the device system locale not working for Indian languages other than Hindi and Bengali
参考 this link,我正在构建一个 android 应用程序,它可以更改 android 设备的系统区域设置。它在印度语言印地语和孟加拉语的情况下工作正常,但对于其他印度语言它不能完全工作(但在某些地区如 am/pm 部分时间部分改变)。我的示例代码片段:
public void toEnglish(View v){
IActivityManager am = ActivityManagerNative.getDefault();
Configuration config;
try {
config = am.getConfiguration();
config.locale = Locale.US;
am.updateConfiguration(config);
//Trigger the dirty bit for the Settings Provider.
BackupManager.dataChanged("com.android.providers.settings");
} catch (Exception e) {
e.printStackTrace();
}
}
public void toHindi(View v) {
IActivityManager am = ActivityManagerNative.getDefault();
Configuration config;
try {
Locale locale = new Locale("hi");
config = am.getConfiguration();
config.locale = locale;
am.updateConfiguration(config);
//Trigger the dirty bit for the Settings Provider.
BackupManager.dataChanged("com.android.providers.settings");
} catch (Exception e) {
e.printStackTrace();
}
}
public void toTamil(View v) {
IActivityManager am = ActivityManagerNative.getDefault();
Configuration config;
try {
Locale locale = new Locale("ta");
config = am.getConfiguration();
config.locale = locale;
am.updateConfiguration(config);
//Trigger the dirty bit for the Settings Provider.
BackupManager.dataChanged("com.android.providers.settings");
} catch (Exception e) {
e.printStackTrace();
}
}
如果我通过 设置 -> 语言和输入 -> 语言[=,我的设备并不支持这些语言19=] 并在那里更改语言,它有效。但是如何以编程方式进行呢?
在初始化语言环境时添加国家/地区字符串对我来说是个窍门。我在这里添加字符串 "IN".
public void toTamil(View v) {
IActivityManager am = ActivityManagerNative.getDefault();
Configuration config;
try {
Locale locale = new Locale("ta","IN");
config = am.getConfiguration();
config.locale = locale;
am.updateConfiguration(config);
//Trigger the dirty bit for the Settings Provider.
BackupManager.dataChanged("com.android.providers.settings");
} catch (Exception e) {
e.printStackTrace();
}
参考 this link,我正在构建一个 android 应用程序,它可以更改 android 设备的系统区域设置。它在印度语言印地语和孟加拉语的情况下工作正常,但对于其他印度语言它不能完全工作(但在某些地区如 am/pm 部分时间部分改变)。我的示例代码片段:
public void toEnglish(View v){
IActivityManager am = ActivityManagerNative.getDefault();
Configuration config;
try {
config = am.getConfiguration();
config.locale = Locale.US;
am.updateConfiguration(config);
//Trigger the dirty bit for the Settings Provider.
BackupManager.dataChanged("com.android.providers.settings");
} catch (Exception e) {
e.printStackTrace();
}
}
public void toHindi(View v) {
IActivityManager am = ActivityManagerNative.getDefault();
Configuration config;
try {
Locale locale = new Locale("hi");
config = am.getConfiguration();
config.locale = locale;
am.updateConfiguration(config);
//Trigger the dirty bit for the Settings Provider.
BackupManager.dataChanged("com.android.providers.settings");
} catch (Exception e) {
e.printStackTrace();
}
}
public void toTamil(View v) {
IActivityManager am = ActivityManagerNative.getDefault();
Configuration config;
try {
Locale locale = new Locale("ta");
config = am.getConfiguration();
config.locale = locale;
am.updateConfiguration(config);
//Trigger the dirty bit for the Settings Provider.
BackupManager.dataChanged("com.android.providers.settings");
} catch (Exception e) {
e.printStackTrace();
}
}
如果我通过 设置 -> 语言和输入 -> 语言[=,我的设备并不支持这些语言19=] 并在那里更改语言,它有效。但是如何以编程方式进行呢?
在初始化语言环境时添加国家/地区字符串对我来说是个窍门。我在这里添加字符串 "IN".
public void toTamil(View v) {
IActivityManager am = ActivityManagerNative.getDefault();
Configuration config;
try {
Locale locale = new Locale("ta","IN");
config = am.getConfiguration();
config.locale = locale;
am.updateConfiguration(config);
//Trigger the dirty bit for the Settings Provider.
BackupManager.dataChanged("com.android.providers.settings");
} catch (Exception e) {
e.printStackTrace();
}