Removing an app icon from launcher


SDK Version: 
M3


Creating an application that does not appear among the launchable applications with an icon is easy.
Just do not put a launcher activity into AndroidManifest.xml

  1. <intent-filter>
  2.   <action android:name="android.intent.action.MAIN" />
  3.   <category android:name="android.intent.category.LAUNCHER" />
  4. </intent-filter>

Removing an application icon after installation programatically is a bit more tricky.
You can not disable the icon itself, but you can disable one component of an application. So disabling the applications launcher activity will result its icon to be removed from launcher.

The code to do this is simple:

  1. ComponentName componentToDisable =
  2.   new ComponentName("com.helloandroid.apptodisable",
  3.   "com.helloandroid.apptodisable.LauncherActivity");
  4.  
  5. getPackageManager().setComponentEnabledSetting(
  6.   componentToDisable,
  7.   PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
  8.   PackageManager.DONT_KILL_APP);

There is a few things to know about this solution:

  • the disabled component will not be launchable in any way
  • other non disabled activities will be launchable from other applications
  • an application can only disable its own component. There is a permission "android.permission.CHANGE_COMPONENT_ENABLED_STATE", but it wont work, 3rd party applications can not have this permission
  • the icon will only disapper when the launcher is restarted, so likely on next phone reboot, forcing the launcher to restart is not recommended