Android14——Launcher3删除“对话”微件、删除“通讯录微件下面的直接拨打电话,直接发送短信两个子微件”

删除“对话”微件

/packages/apps/Launcher3/src_shortcuts_overrides/com/android/launcher3/model/WidgetsModel.java

原始代码:

    public List<ComponentWithLabelAndIcon> update(
            LauncherAppState app, @Nullable PackageUserKey packageUser) {
        Preconditions.assertWorkerThread();

        Context context = app.getContext();
        final ArrayList<WidgetItem> widgetsAndShortcuts = new ArrayList<>();
        List<ComponentWithLabelAndIcon> updatedItems = new ArrayList<>();
        try {
            InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
            PackageManager pm = app.getContext().getPackageManager();

            // Widgets
            WidgetManagerHelper widgetManager = new WidgetManagerHelper(context);
            for (AppWidgetProviderInfo widgetInfo : widgetManager.getAllProviders(packageUser)) {
                LauncherAppWidgetProviderInfo launcherWidgetInfo =
                        LauncherAppWidgetProviderInfo.fromProviderInfo(context, widgetInfo);

                widgetsAndShortcuts.add(new WidgetItem(
                        launcherWidgetInfo, idp, app.getIconCache(), app.getContext()));
                updatedItems.add(launcherWidgetInfo);
            }

            // Shortcuts
            for (ShortcutConfigActivityInfo info :
                    queryList(context, packageUser)) {
                widgetsAndShortcuts.add(new WidgetItem(info, app.getIconCache(), pm));
                updatedItems.add(info);
            }
            setWidgetsAndShortcuts(widgetsAndShortcuts, app, packageUser);
        } catch (Exception e) {
            if (!FeatureFlags.IS_STUDIO_BUILD && Utilities.isBinderSizeError(e)) {
                // the returned value may be incomplete and will not be refreshed until the next
                // time Launcher starts.
                // TODO: after figuring out a repro step, introduce a dirty bit to check when
                // onResume is called to refresh the widget provider list.
            } else {
                throw e;
            }
        }

        return updatedItems;
    }

代码修改:

    public List<ComponentWithLabelAndIcon> update(
            LauncherAppState app, @Nullable PackageUserKey packageUser) {
        Preconditions.assertWorkerThread();

        Context context = app.getContext();
        final ArrayList<WidgetItem> widgetsAndShortcuts = new ArrayList<>();
        List<ComponentWithLabelAndIcon> updatedItems = new ArrayList<>();
        try {
            InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
            PackageManager pm = app.getContext().getPackageManager();

            // Widgets
            WidgetManagerHelper widgetManager = new WidgetManagerHelper(context);
            for (AppWidgetProviderInfo widgetInfo : widgetManager.getAllProviders(packageUser)) {
                LauncherAppWidgetProviderInfo launcherWidgetInfo =
                        LauncherAppWidgetProviderInfo.fromProviderInfo(context, widgetInfo);
				//MengLingbiao add it to remove some widget.[mc45][77391][2024_11_03]
				String packageName = launcherWidgetInfo.getComponent().getPackageName();
				Log.d("mlb","pName:"+packageName);
				if( !packageName.equals("com.android.systemui") ){
					widgetsAndShortcuts.add(new WidgetItem(launcherWidgetInfo, idp, app.getIconCache(), app.getContext()));
					updatedItems.add(launcherWidgetInfo);
				}
				//MengLingbiao add it to remove some widget.[mc45][77391][2024_11_03]
            }

            // Shortcuts
            for (ShortcutConfigActivityInfo info :
                    queryList(context, packageUser)) {
                widgetsAndShortcuts.add(new WidgetItem(info, app.getIconCache(), pm));
                updatedItems.add(info);
            }
            setWidgetsAndShortcuts(widgetsAndShortcuts, app, packageUser);
        } catch (Exception e) {
            if (!FeatureFlags.IS_STUDIO_BUILD && Utilities.isBinderSizeError(e)) {
                // the returned value may be incomplete and will not be refreshed until the next
                // time Launcher starts.
                // TODO: after figuring out a repro step, introduce a dirty bit to check when
                // onResume is called to refresh the widget provider list.
            } else {
                throw e;
            }
        }

        return updatedItems;
    }

我们看一下新增的代码:

				//MengLingbiao add it to remove some widget.[mc45][77391][2024_11_03]
				String packageName = launcherWidgetInfo.getComponent().getPackageName();
				Log.d("mlb","pName:"+packageName);
				if( !packageName.equals("com.android.systemui") ){
					widgetsAndShortcuts.add(new WidgetItem(launcherWidgetInfo, idp, app.getIconCache(), app.getContext()));
					updatedItems.add(launcherWidgetInfo);
				}
				//MengLingbiao add it to remove some widget.[mc45][77391][2024_11_03]

首先,我们获取应用微件的包名,然后通过包名进行过滤,就是找出来这个微件的包名,然后不让这个微件进行添加到集合中,这样也就显示不出来了。

说明:在Widgets这个代码下,显示的包名可能不能包含所有微件,这是因为有一部分是在Shortcuts下进行显示的,所以根据你的需要在上面代码的不同位置进行过滤哦。

删除“通讯录微件下面的直接拨打电话,直接发送短信两个子微件”

/packages/apps/Contacts/AndroidManifest.xml
        <activity-alias
            android:name="alias.DialShortcut"
            android:icon="@drawable/logo_quick_contacts_dialer_color_44in48dp"
            android:label="@string/shortcutDialContact"
            android:exported="true"
            android:targetActivity=".activities.ContactSelectionActivity">

            <intent-filter>
                <action android:name="android.intent.action.CREATE_SHORTCUT"/>

                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.CAR_MODE"/>
            </intent-filter>

        </activity-alias>

        <activity-alias
            android:name="alias.MessageShortcut"
            android:icon="@drawable/logo_quick_contacts_mail_color_44in48dp"
            android:label="@string/shortcutMessageContact"
            android:exported="true"
            android:targetActivity=".activities.ContactSelectionActivity">

            <intent-filter>
                <action android:name="android.intent.action.CREATE_SHORTCUT"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>

        </activity-alias>      

在该文件中找到上面这个代码,直接注释掉,就可以删除这两个子微件,删除子微件的方法是比较简单的,要删除哪个应用的子微件,就去哪个应用的根目录下找AndroidManifest.xml,在这里面找到你要注释掉的微件即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱睡觉的小Meng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值