Change locale system language via ADB in starting from Android 6.0


Question

For manual UI testing purposes, on my Android 6.0 & 7.0 devices, I use a shortcut to access language preferences via ADB, then choose one of the three languages ar_DZ, en_GB, fr_FR manually



adb shell am start -n com.android.settings/.Settings\$LocalePickerActivity


Question: is is possible to automate the task of changing the system locale (without root) via ADB?


Answer

This solution doesn't use directly but meets the end result using automation on unrooted devices



is preferred choice of for me, being simple and free up to 5 macros



Preliminary Steps




  • Install Macrodroid and grant all permissions it asks for


  • Actions desired by OP require root. Macrodroid offers a way to do it by without root using methods, explained here. In essence, it is granting WRITE_SECURE_SETTINGS and CHANGE_CONFIGURATION by running the following commands




adb shell pm grant com.arlosoft.macrodroid android.permission.WRITE_SECURE_SETTINGS



followed by



adb shell pm grant com.arlosoft.macrodroid android.permission.CHANGE_CONFIGURATION



Reboot to ensure commands are updated in the app



Creating Macros and Testing




  • Trigger : Select Empty Trigger


  • Action : Set language → French → France ( corresponding to fr_FR)


  • Constraints : Leave blank


  • Test it by selecting Test Macro from the 3 dots menu of the macro. The system language should change to French . Save the macro for example French. Create two similar macros for other two choices




Creating Home Screen Shortcut



Usually, if you long press the home screen, you will find the icon for widgets collection. Among them you will find Macrodroid widgets. One of them is Macrodroid shortcuts. Drag and drop that to your home screen , it will ask you which macro it should be assigned to , while displaying a list of Macros. Select the macro and rename the widget e.g., French. When you press on that widget corresponding macro is executed. Repeat for other Macros. If you are using a custom launcher you will need to search how to access the widgets collection



Notes




  • Drop down menu selection for languages can be implemented but that would require another Macro. Besides this method of one desktop icon shortcut for each language keeps it simple and easier to debug


  • This method will not work on Oreo (You do not get the set language action, maybe due to the way it is implemented)



Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes