Change device language on Android 6.0 (Android M)

守給你的承諾、 提交于 2019-12-11 03:50: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.



来源:https://stackoverflow.com/questions/32175207/change-device-language-on-android-6-0-android-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!