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

发布于 2024-12-16 10:25:27 字数 116 浏览 0 评论 0原文

我的应用程序设计为只需要运行一次。因此,我想在第一次运行后隐藏启动器中的图标,但不卸载应用程序。

我见过类似的应用程序 - 他们可以从启动器应用程序列表中删除自己的图标。我怎样才能达到相同的结果?谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

遗心遗梦遗幸福 2024-12-23 10:25:28

使用 Android Q (API 29) Google 更改了启动器图标可见性行为。即使您禁用启动器活动或完全删除
android.intent.category.LAUNCHER 从您的所有 Activity 中,应用程序将出现在启动器中并打开 Android 操作系统应用程序设置,但有例外: 未

  • 在各自清单文件中声明任何权限的软件包
  • 系统应用
  • 程序 内部不包含任何组件的应用程序
    各自清单的标签

With Android Q (API 29) Google changed the Launcher icon visibility behaviour. 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:

  • 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
Smile简单爱 2024-12-23 10:25:28

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

You can have an app without a launcher by NOT including an intent filter with MAIN and LAUNCHER in the declaration of the Activity in the AndroidManifest - the question then becomes how to do the first kick off.. Widget maybe ?

雪落纷纷 2024-12-23 10:25:28

使用此代码隐藏应用程序图标:

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

注意:这不适用于 Android 10

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

临风闻羌笛 2024-12-23 10:25:27
PackageManager p = getPackageManager();
p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

请注意,该图标可能要等到下次重新启动后才会消失。

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.

只是在用心讲痛 2024-12-23 10:25:27

使用下面的代码隐藏应用程序的图标

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

// 第一次在声明为 的清单文件中打开的活动

以下是方法恢复应用程序的图标

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

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" />

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文