'How to hide App icon from launcher in Android 10 and higher

I know there is a way to hide app icon in Android 9(API 28) and lower. But is there a work around to make the same happen in Android 10(Api 29).

The code below doesn't work for API 29.

         val p: PackageManager? = context?.packageManager
            val componentName = context?.let {
                ComponentName(
                    it,
                    MainActivity::class.java
                )
            } // activity which is first time open in manifiest file which is declare as <category android:name="android.intent.category.LAUNCHER" />

            if (componentName != null) {
                p?.setComponentEnabledSetting(
                    componentName,
                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP
                )
            }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source