隐藏APP启动图标,网上说使用COMPONENT_ENABLED_STATE_DISABLED隐藏后不能显示,需要使用COMPONENT_ENABLED_STATE_DISABLED_USER,我没有出现这个情况。
LaunchActivity为对应的禁用activity,我们把启动图标设置放在这个activity中,在禁用后,就看不到该图标了,也不能通过startActivity来启动该activity了,所以我们还需要在manifest中注册真正的activity,这样setComponentEnabledSetting就不会影响真正的activity的调用了。
public static void hideAppIcon(Context context) { ComponentName componentName = new ComponentName(context, "my.package.LaunchActivity"); PackageManager packageManager = context.getPackageManager(); int state = packageManager.getComponentEnabledSetting(componentName); if (state != PackageManager.COMPONENT_ENABLED_STATE_DISABLED) { packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); }}
显示APP启动图标
public static void showAppIcon(Context context) { ComponentName componentName = new ComponentName(context, "my.package.LaunchActivity"); PackageManager packageManager = context.getPackageManager(); int state = packageManager.getComponentEnabledSetting(componentName); if (state != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP); }}