3

I have apk file of the application undertest(no source code,is robotium UI automated-tests).I need to change system locale automatically via code. Could anyone give me a mechanism or way to solve this problem?

Someone recommended me this code:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.LanguageSettings");            
startActivity(intent);

It helps me to open Settings->Language & Input, but i need to select one language automatically via code(Because it is requirement for robotium automated-tests).

Please give me a specific process of solution.

Thanks

Almett
  • 876
  • 2
  • 11
  • 34
  • Possible duplicate of [Change language settings (locale) for the device](http://stackoverflow.com/questions/2596352/change-language-settings-locale-for-the-device) – vallentin Nov 09 '15 at 04:03
  • Actually i tried this approach ,it works. but i neet to click one of the languages automatically via code. How can i do this? Better to show with codes. Thanks – Almett Nov 09 '15 at 06:13
  • @Vallentin I edited my question above. Please let me know if there is any solution to solve my problem.Thanks – Almett Nov 09 '15 at 07:20

1 Answers1

1

Do like this if you want for example to change your app language:

Resources res = getResources();
                // Change locale settings in the app.
                DisplayMetrics dm = res.getDisplayMetrics();
                android.content.res.Configuration conf = res.getConfiguration();
                conf.locale = new Locale(/* your language here */);
                res.updateConfiguration(conf, dm);
Virthuss
  • 3,142
  • 1
  • 21
  • 39
  • This is likely not what i need.This approach is for changing locale of Application. – Almett Nov 09 '15 at 06:15
  • What i need to do is change locale of android system automatically via code .Any good solution for this? – Almett Nov 09 '15 at 06:43
  • I know that it's possible but I don't know how personally, as it's not very common. My bad for the answer, I didn't understand your problem well. – Virthuss Nov 09 '15 at 06:48