MrOnlineCoder February 2016

How does MoreLocale work?

I downloaded source code, and seems that there is something connected with Android Settings. I want to implement some it's features in my application. How it works?

Answers


MrOnlineCoder February 2016

Finally I found a way to set Android system locale:

public void changeLanguage() {
IActivityManager am = ActivityManagerNative.getDefault();
Configuration config;
try {
    config = am.getConfiguration();

    config.locale = Locale.US; // Change it to your locale

    config.userSetLocale = true;

    am.updateConfiguration(config);
    BackupManager.dataChanged("com.android.providers.settings");
} catch (RemoteException e) {
    e.printStackTrace();
}
}

It also requires CHANGE_CONFIGURATION permission:

<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />

NOTE: In Android 4.2 or newer, permission policy has been changed, and 3rd party application can't get this permission. If you have root access, execute pm grant command:

String.format("pm grant $1%s android.permission.CHANGE_CONFIGURATION", new Object[]{getPackageName()})

Post Status

Asked in February 2016
Viewed 2,836 times
Voted 5
Answered 1 times

Search




Leave an answer