Android以编程方式隐藏/取消隐藏应用程序图标

标签 android android-package-managers

我使用下面的代码以编程方式隐藏应用程序图标

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/

相关文章:

Android ActionBarCompat 从一开始就不工作

android - Android 中包管理器的 Aidl 代码链接

安卓 : what is canonical package name?

android - 在 Android 上以编程方式关闭应用程序的通知

android - 如何同时监听触摸事件和软键盘事件

java - fragment 中的 Recyclerview,跳过未附加适配器的布局

android - TextView setText 不刷新文本

android - 如何获取访问我的应用程序内容提供者的应用程序包名称?

android - Android PackageManager 是否会接受声明 systemOrSignature 权限的应用程序?

android - 如何使用循环在 firebase 中插入多个数据