2

I need to develop an app which on installation onto a Jelly Bean Device will change OS language into Spanish, just that. Run in silent mode, no need to interact with end-user, no need to chose another language or revert the change. Just install the app and change device into Spanish language

I've seen lot of examples on the web but none is working well for me. I know how to run Android Studio and accommodate the code I find but its never working correctly.

Actually I was trying with something like this (but with no success)

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
   String languageToLoad  = "es_ES"; // 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.activity_main);
}

}
Veve
  • 6,643
  • 5
  • 39
  • 58
Juan_Lara
  • 73
  • 12
  • You can't change OS language settings, that would be a huge security hole. – Jehy Aug 22 '16 at 08:18
  • Hi Jehy, thanks for your response. I understand what you mean but then, why applications like this one "https://apkpure.com/adb-change-language/net.sanapeli.adbchangelanguage" are able to do it (and very well). Indeed, you can change it through an ADB command in background. – Juan_Lara Aug 22 '16 at 08:24
  • Yup, this one works because it uses adb which can grant such permission. Check description: `Usage: - install this app - setup adb connection to your device (http://developer.android.com/tools/help/adb.html) - Android OS 4.2 onwards (tip: you can copy the command here and paste it to your command console): adb shell pm grant net.sanapeli.adbchangelanguage android.permission.CHANGE_CONFIGURATION` – Jehy Aug 22 '16 at 09:27
  • Also see this question: http://stackoverflow.com/questions/21712205/change-device-language-via-adb – Jehy Aug 22 '16 at 09:28
  • Hi Jehy, thanks again. My device is JellyBean 4.1.1. With adb, is not possible to do it (in your link, there´s a reference that only in 4.2+ are available). That´s the reason I was surprise this application I referenced before was able to change the language. I thought perhaps it was a mix of a Java application and adb command which allow me to make the change. – Juan_Lara Aug 22 '16 at 11:56
  • change os language for all apps on the device or just for the current app? – k3b Aug 22 '16 at 12:49
  • Hi, This is the code that was finally working for me – Juan_Lara Aug 30 '16 at 10:32

0 Answers0