48

my app is designed to only need to be run once. As such I want to hide the icon from the launcher after the first run, but without uninstalling the app.

I have seen similar applications - they can remove their own icons from the launcher app list. How can I achieve the same results? Thank you.

user1047351
  • 481
  • 1
  • 5
  • 3
  • 7
    Never seen that to be honest, out of curiosity: Can you name one or two apps that do that? –  Nov 15 '11 at 10:31
  • i'm curious too , plz name one or two apps which can remove their own icons from the launcher app list. thank you – Houcine Nov 15 '11 at 10:54
  • http://stackoverflow.com/questions/1103027/how-to-change-an-application-icon-programmatically-in-android – Arun Badole Nov 15 '11 at 11:12
  • 1
    Unfortunately I forgot which application but I'll reply here if I come across it again... – user1047351 Nov 30 '11 at 02:47
  • 1
    The application is "Smart Keyboard Pro". In its settings, there is an option to remove the launcher icon. – user1047351 Dec 27 '11 at 04:05

5 Answers5

65
PackageManager p = getPackageManager();
p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

Note that the icon may not be gone until the next reboot.

Kuffs
  • 35,581
  • 10
  • 79
  • 92
  • Thanks, but if I use this, will I be able to update my application via Market? – user1047351 Nov 18 '11 at 09:59
  • Yes I use this myself in one of my own apps. – Kuffs Nov 18 '11 at 10:21
  • 1
    then how do you define a shortkey to actually launch your app – png Apr 30 '12 at 12:23
  • 3
    when i do this and try to reinstall my app , its not working. It says activity (the one disbaled) doesnot exist. Can you please help how to handle it – png May 01 '12 at 13:01
  • 4
    OP, kindly accept one of the answers as they seem to solve your problem – Dheeraj Bhaskar Dec 18 '12 at 08:41
  • How can I call this in a different activity to the one I want to disable? – Liam W Jan 06 '13 at 13:09
  • Hi @Kuffs This solution really works, but my app cannot Received a GCM message. How can my app receive GCM message even if the icon laucher is hidden? – jayellos Feb 28 '13 at 09:56
  • @Kuffs i had used this method and open applcation when message receive menac in brodcast recerver i had open application but when i used this code to hide app and recever start activity it's crase that activity not found while without code when message receve it's perfectly open. can u help me? – CoronaPintu Sep 30 '13 at 11:07
  • I am also facing the same problem as @pintu – Shivang Gupta Feb 01 '14 at 18:29
  • @SHIVANGSANGHI once you hide apps it will destroy that activity so you need to open another activity when you open it – CoronaPintu Feb 03 '14 at 04:38
  • It does not allows the application to run further... seems it is killing the app – Noman May 27 '14 at 07:30
  • 1
    I really taught this was more complicated but this answer worked flawlessly. NOTE: Problems caused by this when you try to uninstall is because your only exported component (activity marked with main and launcher) is disabled by this. You can add some other exported component to get back into the app (for example register broadcast receiver for GCM or SMS receive). Similar approach needs to be done to re-enable re-installing from play store (and even from eclipse) but I am not certain what component needs to be added. – Igor Čordaš Nov 16 '14 at 20:13
13

Hide app's icon using below code

PackageManager pkg=this.getPackageManager();
pkg.setComponentEnabledSetting(new ComponentName(this,SplashActivity.class),PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);

// activity which is first time open in manifiest file which is declare as <category android:name="android.intent.category.LAUNCHER" />

Here is how to bring back the app's icon

PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this,SplashActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Amsheer
  • 7,046
  • 8
  • 47
  • 81
Sahir Saiyed
  • 518
  • 8
  • 17
9

With Android Q (API 29) Google changed the Launcher icon visibility behaviour. Even if you disable your Launcher Activity or completely remove the android.intent.category.LAUNCHER <intent-filter> from all your Activities, the app will appear in the launcher and open the Android OS app settings, with the exception of:

  • Packages that don't declare any permissions in their respective manifest files
  • System apps
  • Apps that don't contain any components inside their respective manifest's tag
cuzi
  • 978
  • 10
  • 21
G00fY
  • 4,545
  • 1
  • 22
  • 26
1

You can have an app without a launcher by NOT including an intent filter with MAIN and LAUNCHER in the declaration of the Activity in the AndroidManifest - the question then becomes how to do the first kick off.. Widget maybe ?

Clocker
  • 1,316
  • 2
  • 19
  • 29
  • 1
    I don't think OP meant the icon that is created "on the desktop", but rather the icon in the "app drawer". Also.. maybe you can open it using the "open" button in the play store after installing. – Dev-iL Mar 06 '17 at 16:08
1

Hide app icon using this 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);

and bring it back, with this:

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: This will not work for Android 10

Rohit Nishad
  • 2,570
  • 2
  • 22
  • 32
  • 1
    is there any possibility for android 10 hide icon with admin permission or like this ? – Ahmad Dec 17 '20 at 10:55