Android hide/unhide app icon programmatically
Hide app's icon using below 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);
Here is how to bring back the app's icon.
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, com.apps.MainActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Important Edit:
According to docs, as of Android Q (API 29) all app icons will be visible in the launcher no matter what unless:
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 hide app icon programmatically just works in my packagename
This means that i can hide my app icon only?
Correct. There may be some options for doing this as a device owner app, but ordinary apps cannot disable other apps.
How to hide/unhide an application from Launcher when the application uses a permission?
I'm not sure if "officially not supported" is an answer or not. But unfortunately, according to docs:
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.
Related Topics
Programmatically Update Widget from Activity/Service/Receiver
Android Dependency Has Different Version for the Compile and Runtime
How to Set Internet Options for Android Emulator
How to Split Comma-Separated Value in SQLite
Disable Activity Slide-In Animation When Launching New Activity
Setuservisiblehint Called Before Oncreateview in Fragment
How to Get the List of Mounted External Storage of Android Device
Cursor Size Limit in Android SQLitedatabase
What's Dp (Density Independent Pixels) Units with CSS
How to Check the Internet Connection in Android
No Actionbar in Preferenceactivity After Upgrade to Support Library V21
Adb Root Is Not Working on Emulator (Cannot Run as Root in Production Builds)
Removing Log Call Using Proguard
Error Java.Lang.Classnotfoundexception: Com.Google.Android.Gms.Maps.Mapfragment in Google Map V2
Android - Drawable with Rounded Corners at the Top Only
Listview with Add and Delete Buttons in Each Row in Android
How to Turn On/Off Wifi Hotspot Programmatically in Android 8.0 (Oreo)