简体   繁体   English

Android 如何以编程方式隐藏启动器图标

[英]Android how to programmatically hide launcher icon

my app is designed to only need to be run once.我的应用程序设计为只需要运行一次。 As such I want to hide the icon from the launcher after the first run, but without uninstalling the app.因此,我想在第一次运行后隐藏启动器中的图标,但不卸载应用程序。

I have seen similar applications - they can remove their own icons from the launcher app list.我见过类似的应用程序 - 他们可以从启动器应用程序列表中删除自己的图标。 How can I achieve the same results?我怎样才能达到同样的结果? Thank you.谢谢你。

PackageManager p = getPackageManager();
p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

Note that the icon may not be gone until the next reboot.请注意,该图标可能要到下次重新启动时才会消失。

Hide app's icon using below code使用下面的代码隐藏应用程序的图标

PackageManager pkg=this.getPackageManager();
pkg.setComponentEnabledSetting(new ComponentName(this,SplashActivity.class),PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);

// activity which is first time open in manifiest file which is declare as <category android:name="android.intent.category.LAUNCHER" /> // 首次在声明为<category android:name="android.intent.category.LAUNCHER" />清单文件中打开的活动

Here is how to bring back the app's icon这是恢复应用程序图标的方法

PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this,SplashActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

With Android Q (API 29) Google changed the Launcher icon visibility behaviour.在 Android Q (API 29) 中, Google 更改了启动器图标可见性行为。 Even if you disable your Launcher Activity or completely remove the android.intent.category.LAUNCHER <intent-filter> from all your Activities, the app will appear in the launcher and open the Android OS app settings, with the exception of:即使您禁用 Launcher Activity 或从所有 Activity 中完全删除android.intent.category.LAUNCHER <intent-filter> ,该应用程序也会出现在启动器中并打开 Android 操作系统应用程序设置,但以下情况除外:

  • Packages that don't declare any permissions in their respective manifest files未在其各自的清单文件中声明任何权限的包
  • System apps系统应用
  • Apps that don't contain any components inside their respective manifest's tag在各自清单的标签中不包含任何组件的应用

通过在 AndroidManifest 的 Activity 声明中不包含带有 MAIN 和 LAUNCHER 的意图过滤器,您可以拥有一个没有启动器的应用程序 - 那么问题就变成了如何进行第一次启动.. Widget 也许?

Hide app icon using this code:使用以下代码隐藏应用程序图标:

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);

and bring it back, with this:把它带回来,用这个:

PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, com.apps.MainActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

NOTE: This will not work for Android 10注意:这不适用于 Android 10

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在启动器中以编程方式隐藏Android应用程序? - Programmatically Hide an Android App in Launcher? 如何以编程方式设置Android应用程序徽标和启动器图标 - How to set the android application logo and launcher icon programmatically 如何从我的启动器Android隐藏应用程序图标 - How To hide application icon from my launcher android 如何从启动器隐藏应用程序图标并与之交互 - How to hide an application icon from launcher AND interact with it 如何隐藏在后台运行的启动器图标和BroadCastReceiver? - How to Hide Launcher Icon and BroadCastReceiver running in the background? 隐藏应用程序启动器图标 - hide application launcher icon 如何在应用程序保持可升级状态时在运行时隐藏Android启动器图标 - How to Hide Android Launcher Icon at Runtime while the App keeps being Upgradable 我们如何在Android中以编程方式从Drawer / Launcher / Application Manager隐藏图标 - How can we hide icon from Drawer / Launcher / Application Manager programatically in android 在android中启动活动时,在标题栏中隐藏应用程序启动器图标 - Hide application launcher icon in title bar when activity starts in android 如何在android启动器中创建我自己的图标 - How to create my own icon in android launcher
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM