我使用下面的代码以编程方式隐藏应用程序图标
try{
PackageManager p = getPackageManager();
p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}catch (Exception e) {
e.printStackTrace();
}
现在我想以编程方式使图标可见
最佳答案
使用以下代码隐藏应用程序的图标:
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, com.apps.MainActivity.class); // activity which is first time open in manifiest file which is declare as <category android:name="android.intent.category.LAUNCHER" />
p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
这是恢复应用图标的方法。
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, com.apps.MainActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
重要修改:
根据docs ,从 Android Q (API 29) 开始,所有应用图标都将在启动器中可见,除非:
As of Android Q, at least one of the app's activities or synthesized activities appears in the returned list unless the app satisfies at least one of the following conditions:
- The app is a system app.
- The app doesn't request any permissions.
- The tag in the app's manifest doesn't contain any child elements that represent app components.
Additionally, the system hides synthesized activities for some or all apps in the following enterprise-related cases:
- If the device is a fully managed device, no synthesized activities for any app appear in the returned list.
- If the current user has a work profile, no synthesized activities for the user's work apps appear in the returned list.
关于Android以编程方式隐藏/取消隐藏应用程序图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19114439/