Lucas S.
Lucas S.

Reputation: 13541

Remove application from launcher programmatically in Android

Is there a way of removing an activity from the home launcher at runtime? I mean removing Intent.CATEGORY_LAUNCHER from its properties or something similar.

Upvotes: 18

Views: 10394

Answers (2)

Ajay Vishwakarma
Ajay Vishwakarma

Reputation: 327

Actually from Android 10+, it is quite difficult to hide the app launcher icon. I have used the code -

               val packageManager = packageManager

                **// disable the app launcher icon**
                val componentName = ComponentName(
                    this,
                    MainActivity::class.java
                )
                packageManager.setComponentEnabledSetting(
                    componentName,
                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP
                )

               **// enable the app launcher icon**
                val componentName = ComponentName(
                    this,
                    MainActivity::class.java
                )

                packageManager.setComponentEnabledSetting(
                    componentName,
                    PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                    PackageManager.DONT_KILL_APP
                )

When the disable code runs, it only makes the app launcher icon disabled, not hidden. But you cannot launch it, it opens the app info setting page when clicking the launcher icon.

Another way - This is another way to do that: make an app and run it in device owner mode. Then we will be able to hide/remove the app launcher icon.

Visit the link- https://www.sisik.eu/blog/android/dev-admin/uninstalling-and-disabling-apps

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1006674

You can disable a component via PackageManager#setComponentEnabledSetting(), which will have the effect of removing it from the Launcher.

Upvotes: 12

Related Questions