11package com .hjq .language ;
22
33import android .app .Application ;
4- import android .app .LocaleManager ;
54import android .content .Context ;
65import android .content .res .Resources ;
7- import android .os .Build ;
8- import android .os .LocaleList ;
96import android .os .Looper ;
107import android .os .MessageQueue ;
118import android .text .TextUtils ;
@@ -43,6 +40,7 @@ public static void init(final Application application, boolean inject) {
4340 if (inject ) {
4441 ActivityLanguages .inject (application );
4542 }
43+ /*
4644 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
4745 LocaleManager localeManager = application.getSystemService(LocaleManager.class);
4846 if (localeManager != null) {
@@ -59,6 +57,7 @@ public static void init(final Application application, boolean inject) {
5957 }
6058 }
6159 }
60+ */
6261 // 等所有的任务都执行完了,再设置对系统语种的监听,用户不可能在这点间隙的时间完成切换语言的
6362 // 经过实践证明 IdleHandler 会在第一个 Activity attachBaseContext 之后调用的,所以没有什么问题
6463 Looper .myQueue ().addIdleHandler (new MessageQueue .IdleHandler () {
@@ -123,9 +122,11 @@ public static Locale getAppLanguage(Context context) {
123122 * @return 语种是否发生改变了
124123 */
125124 public static boolean setAppLanguage (Context context , Locale newLocale ) {
126- //if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
127- // context.getSystemService(LocaleManager.class).setApplicationLocales(new LocaleList(newLocale));
128- //}
125+ /*
126+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
127+ context.getSystemService(LocaleManager.class).setApplicationLocales(new LocaleList(newLocale));
128+ }
129+ */
129130 // 这里解释一下,在 Android 13 上为什么不用 LocaleManager.setApplicationLocales 来设置语种,原因如下:
130131 // 1. 调用此 API 会自动重启 Activity,而框架是将重启操作放到了外层给开发者去重启
131132 // 2. 上面说了,调用此 API 会重启 Activity,重启也就算了,还顺带闪了一下,这个不能忍
0 commit comments