更改Android Jelly Bean设备中的操作系统语言设置
我需要开发一个应用程序,在安装到Jelly Bean设备上时,它会将操作系统语言更改为西班牙语,仅此而已。以静默模式运行,无需与最终用户交互,无需选择其他语言或还原更改。只需安装应用程序并将设备更改为西班牙语即可 我在网上看到了很多例子,但没有一个对我有效。我知道如何运行androidstudio并适应我找到的代码,但它永远不会正常工作 实际上我是在尝试这样的事情(但没有成功)更改Android Jelly Bean设备中的操作系统语言设置,android,Android,我需要开发一个应用程序,在安装到Jelly Bean设备上时,它会将操作系统语言更改为西班牙语,仅此而已。以静默模式运行,无需与最终用户交互,无需选择其他语言或还原更改。只需安装应用程序并将设备更改为西班牙语即可 我在网上看到了很多例子,但没有一个对我有效。我知道如何运行androidstudio并适应我找到的代码,但它永远不会正常工作 实际上我是在尝试这样的事情(但没有成功) 请使用此代码fa=波斯语。。。英语。。。 在languageToLoad中输入您的语言代码: import andro
请使用此代码fa=波斯语。。。英语。。。 在languageToLoad中输入您的语言代码:
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String languageToLoad = "fa"; // your language
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
this.setContentView(R.layout.main);
}
}
您无法更改操作系统语言设置,这将是一个巨大的安全漏洞。嗨,杰希,谢谢您的回复。我理解你的意思,但是,为什么像这样的应用程序“”能够做到这一点(而且非常好)。事实上,您可以在后台通过ADB命令对其进行更改。是的,这个命令之所以有效,是因为它使用ADB来授予这样的权限。检查说明:
用法:-安装此应用程序-设置与设备的adb连接(http://developer.android.com/tools/help/adb.html)-Android OS 4.2及以上版本(提示:您可以在此处复制命令并将其粘贴到您的命令控制台):adb shell pm grant net.sanapeli.adbchangelanguage android.permission.CHANGE\u CONFIGURATION
另请查看此问题:嗨,杰希,再次感谢。我的设备是Jellybean4.1.1。对于adb,这是不可能做到的(在你的链接中,有一个参考,只有4.2+中提供)。这就是为什么我很惊讶我之前引用的这个应用程序能够改变语言。我想这可能是Java应用程序和adb命令的混合,允许我进行更改。顺便说一下,我复制并运行了它,结果是一样的。语言未更改。此工作代码仅更改当前活动的语言。
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String languageToLoad = "fa"; // your language
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
this.setContentView(R.layout.main);
}
}