MTK 切换语言后,桌面上的快捷方式名称没有切换到当前语言

本文介绍了一种解决Google桌面快捷方式名称未随系统语言变化而更新的方法。通过修改LauncherModel.java中的loadWorkspace()方法及新增getShortcutTitle()方法,实现了桌面图标语言的实时同步。

切换语言后,桌面上的快捷方式名称没有切换到当前语言


这个是google默认设计,如果要修改的话,请按照以下步骤操作:

1、请修改LauncherModel.java的loadWorkspace()方法,修改为如下:

......

                             if (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {

                                    info = getShortcutInfo(manager, intent, context, c, iconIndex,

                                            titleIndex, mLabelCache);

                                } else {

                                    info = getShortcutInfo(c, context, iconTypeIndex,

                                            iconPackageIndex, iconResourceIndex, iconIndex,

                                            titleIndex);

 

                                    //mtk add begin

                                    CharSequence title = getShortcutTitle(manager, intent);

                                    if(title != null ){

                                                info.title = title;

                                    }

                                    //mtk add end

 

                                    // App shortcuts that used to be automatically added to Launcher

                                    // didn't always have the correct intent flags set, so do that

                                    // here

                                    if (intent.getAction() != null &&

                                        intent.getCategories() != null &&

                                        intent.getAction().equals(Intent.ACTION_MAIN) &&

                                        intent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) {

                                        intent.addFlags(

                                            Intent.FLAG_ACTIVITY_NEW_TASK |

                                            Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

                                    }

                                }

......

 

2、请在LauncherModel.java增加如下方法:

                                private CharSequence getShortcutTitle(PackageManager manager, Intent intent) {

                                                ComponentName componentName = intent.getComponent();

                                                if (componentName == null) {

                                                                return null;

                                                }

                                                try {

                                                                PackageInfo pi = manager.getPackageInfo( componentName.getPackageName(), 0);

                                                                if (!pi.applicationInfo.enabled) {

                                                                                // If we return null here, the corresponding item will be

                                                                                // removed from the launcher

                                                                                // db and will not appear in the workspace.

                                                                                return null;

                                                                }

                                                } catch (NameNotFoundException e) {

                                                                Log.d(TAG, "getPackInfo failed for package " + componentName.getPackageName());

                                                }

 

                                                ResolveInfo resolveInfo = manager.resolveActivity(intent, 0);

 

                                                if (resolveInfo != null) {

                                                                return resolveInfo.activityInfo.loadLabel(manager);

                                                }

                                                return null;

                                }

 
PS:标注为黄色的代码即为修改的代码

参考的引用内容中未提及在MTK平台上指定某些APK不能切换语言的方法。不过,一般在Android平台(MTK是广泛应用于Android设备的芯片平台)可通过以下思路实现: ### 方案一:修改APK代码 在APK的代码层面进行处理,重写语言切换相关的方法,使其不响应系统语言变化。例如在Activity的`attachBaseContext`方法中固定语言设置: ```java @Override protected void attachBaseContext(Context newBase) { // 固定语言为英文 Locale locale = new Locale("en"); Configuration config = newBase.getResources().getConfiguration(); config.setLocale(locale); Context context = newBase.createConfigurationContext(config); super.attachBaseContext(context); } ``` ### 方案二:系统层面定制 如果要从MTK平台系统层面来限制某些APK切换语言,可以通过修改系统源码实现。 1. 找到系统处理语言切换的相关代码,通常在`frameworks`目录下的`base`模块中。 2. 在语言切换逻辑里添加判断,如果是指定的APK包名,则不执行语言切换操作。示例伪代码如下: ```java // 获取当前切换语言的应用包名 String packageName = getCurrentPackageName(); // 指定不允许切换语言的APK包名列表 List<String> restrictedPackages = Arrays.asList("com.example.app1", "com.example.app2"); if (restrictedPackages.contains(packageName)) { // 不执行语言切换逻辑 return; } // 正常执行语言切换逻辑 switchLanguage(); ``` ### 方案三:使用MTK提供的定制工具 MTK提供了大量的软件工具和硬件平台支持开发者进行设备定制和优化,可查看MTK官方文档或相关开发工具,看是否有直接配置某些APK不能切换语言的功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值