Android How to Programmatically Hide Launcher Icon

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 android app from launcher

You need to remove the following line from your AndroidManifest.xml:

<category android:name="android.intent.category.LAUNCHER"/>

This will remove the application from the default launcher. However, you also need to add the following line such that your BroadcastReceiver is not completely ignored:

<category android:name="android.intent.category.DEFAULT"/>

You should NOT remove the line below - it is used to specify which Activity should launch first when your app is opened:

<action android:name="android.intent.action.MAIN"/>

EDIT

In order to launch the application discussed above from another application, you cannot use the calls shown in your question. You are trying to open the application by creating an Intent with the CATEGORY_LAUNCHER tag (i.addCategory(Intent.CATEGORY_LAUNCHER)) when you have explicitly removed the following line from your AndroidManifest.xml file:

<category android:name="android.intent.category.LAUNCHER" />

The absence of the above line means that the application you are trying to call will ignore the launch Intent. In order to launch your application you will need to act upon another Intent. Here is an example that shows how to open an application, which doesn't contain a launch intent filter, by responding to a SMS Intent: How to launch an Android app without "android.intent.category.LAUNCHER"

Which intent you choose to use is up to you - just make sure you add it to your AndroidManifest.xml file.



Related Topics



Leave a reply



Submit