Hide app icon in launcher

Hide specific app icons

1、com/android/launcher3/AppFilter.java

package com.android.launcher3;

import android.content.ComponentName;
import android.content.Context;
import com.android.launcher3.util.ResourceBasedOverride;

public class AppFilter implements ResourceBasedOverride {
    
    
    //这里可以看出反射app_filter_class字符串的配置初始化具体的类
    //我们就可以写一个类继承AppFilter,重写shouldShowApp方法 实现屏蔽
    public static AppFilter newInstance(Context context) {
    
    
        return Overrides.getObject(AppFilter.class, context, R.string.app_filter_class);
    }
    public boolean shouldShowApp(ComponentName app) {
    
    
        return true;
    }
}

2. res configuration

<string name="app_filter_class" translatable="false">com.android.launcher3.CustomAppFilter</string>

3、com/android/launcher3/CustomAppFilter.java

package com.android.launcher3;
import android.content.ComponentName;
import android.content.Context;
import java.util.Arrays;

public class CustomAppFilter extends AppFilter {
    
    
   private String[]  HIDE_PACKAGE = {
    
    "com.google.android.documentsui","cn.com.blacksesame.stereocalib2","com.android.documentsui"};
    public CustomAppFilter(Context context) {
    
    
    }
    @Override
    public boolean shouldShowApp(ComponentName app) {
    
    
      if(Arrays.asList(HIDE_PACKAGE).contains(app.getPackageName())) {
    
    
         return false;
      } else {
    
    
         return true;
      }
    }
}

4. The above only shields the application icon loading process.
If some applications are connected to the external network after logging in to Google Play, the additional icons sent by the three-party apk and added to the desktop need to be filtered separately.

--- a/packages/apps/Launcher3/src/com/android/launcher3/model/AddWorkspaceItemsTask.java
+++ b/packages/apps/Launcher3/src/com/android/launcher3/model/AddWorkspaceItemsTask.java
@@ -15,13 +15,16 @@
  */
package com.android.launcher3.model;
+import android.content.ComponentName;
import android.content.Intent;
import android.os.UserHandle;
+import android.util.Log;
import android.util.LongSparseArray;
import android.util.Pair;
import com.android.launcher3.AllAppsList;
import com.android.launcher3.AppInfo;
+import com.android.launcher3.CustomAppFilter;
import com.android.launcher3.FolderInfo;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.ItemInfo;
@@ -44,7 +47,7 @@ import java.util.List;
public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
    
    
     private final List<Pair<ItemInfo, Object>> mItemList;
-
+    private static final String TAG = "AddWorkspaceItemsTask";
     /**
      * @param itemList items to add on the workspace
      */
@@ -101,6 +104,22 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
    
    
                     throw new RuntimeException("Unexpected info type");
                 }
+                //
+                if(item!=null && item.getTargetComponent()!=null){
    
    
+                    ComponentName cn = item.getTargetComponent();
+                    String pn = cn.getPackageName();
+                    if(pn!=null){
    
    
+                        CustomAppFilter caf = new CustomAppFilter(app.getContext());
+                        if(!caf.shouldShowApp(cn))
+                        {
    
    
+                            Log.d(TAG,"execute continue pn "+ pn +" item: "+item);
+                            Log.d(TAG,"execute Throwable "+Log.getStackTraceString(new Throwable()));
+                            continue;
+                        }
+                    }
+                }
+                //
+
                 // Add the shortcut to the db
                 getModelWriter().addItemToDatabase(itemInfo,
                         LauncherSettings.Favorites.CONTAINER_DESKTOP, screenId,

Guess you like

Origin blog.csdn.net/a396604593/article/details/129796443