How to hide an app icon in Android programmatically from the default launcher without rooting the phone
Since You asked Programmatically
Hide app's icon using below code:
- PackageManager p = getPackageManager();
- ComponentName componentName = new ComponentName(this, com.apps.MainActivity.class); // launcher activity specified in manifest file as
- 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);
Note: It's somehow tricky if you need to do something with main activity in your app when it's hidden. you will face an ActivityNotFoundException. to make it work, you should unhide icon before doing anything to your main activity and hide it again after you are finished.
simple steps: 1-call recebido aqui
2-unhide icon
3-launch actividade principal
4-do your things on main activity
5-hide icon again
Source