删除“对话”微件
/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,在这里面找到你要注释掉的微件即可。
标签:删除,widgetsAndShortcuts,app,launcherWidgetInfo,add,通讯录,new,微件 From: https://blog.csdn.net/qq_45696288/article/details/143626292