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
Android Sdk: Get Raw Preview Camera Image Without Displaying It
App Always Starts Fresh from Root Activity Instead of Resuming Background State (Known Bug)
Setexactandallowwhileidle - Is Not Exact as of Developer Reference
Parcelable Encountered Ioexception Writing Serializable Object Getactivity()
Androidstudio - Module Dependencies in Gradle
How to Put the Text on the Left of a Radio Button in Android
How to Customize List Preference Radio Button
Running Task Periodicaly(Once a Day/Once a Week)
How to Close All the Activities of My Application
Highlight Custom Listview Item When Long Click
Android Button Has Setontouchlistener Called on It But Does Not Override Performclick
How to Check If an App Is a Non-System App in Android
Android: Adding Static Header to the Top of a Listactivity
Android Fragment Onrestoreinstancestate
Can't Upgrade Android Sdk Tools
Multiple Dex Files Define Lorg/Apache/Cordova/Buildhelper
How to Be Notified on Wifi Network Status Change
Bitmap Is Returning Null from Bitmapfactory.Decodefile(Filename)