Change device language on Android 6.0 (Android M)

2019-07-14 01:02发布

问题:

There are applications to change Android device language (locale) via an ADB command. This has required granting the CHANGE_CONFIGURATION permission for the app before language can be changed.

On Android 6.0 (API level 23, Nexus 6 device), however, granting the required permission is no longer allowed, since the command adb shell pm grant net.sanapeli.adbchangelanguage android.permission.CHANGE_CONFIGURATION (package name from ADB Change Language app as an example) yields

Operation not allowed: java.lang.SecurityException: Permission android.permission.CHANGE_CONFIGURATION is not a changeable permission type

How can you change the language/locale on Android OS version 6.0 without rooting the device? Can this be done with a helper app, or a direct ADB command, or by launching some intent vai ADB?

Related question from 2010: Change language programmatically in Android

回答1:

The SecurityException no longer exists on the public image of Android OS 6.0 (Marshmallow) version. This was confirmed on Nexus 6 and Nexus 9 devices. Case closed.



回答2:

I was able to get this working by putting my app in /system/priv-app, so it becomes a privileged system app. As root:

mount -o remount,rw /system
mkdir /system/priv-app/MyApp
cp /sdcard/myapp.apk /system/priv-app/MyApp/MyApp.apk
chcon "u:object_r:system_file:s0" /system/priv-app/MyApp
chcon "u:object_r:system_file:s0" /system/priv-app/MyApp/MyApp.apk
mount -o remount,ro /system

Chcon sets the proper SELinux security context.