I am creating an application in which i need to hide icon launcher and show icon launcher on request. I used below code to hide launcher icon.
<category android:name="android.intent.category.LAUNCHER" /> // Remove this line from manifest.xml
or
PackageManager p = getPackageManager();
p.setComponentEnabledSetting(getComponentName(),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
By using these snippet of code, I am only able to hide application icon.
In order to show i used these code snippet
PackageManager p = getPackageManager();
p.setComponentEnabledSetting(getComponentName(),
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);
and
PackageManager p = getPackageManager();
p.setComponentEnabledSetting(getComponentName(),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
But none of them is effecting or i am not able to retrieve launcher icon back programmatically. Please suggest me how can i achieve this task.
Thanks in advance
The user opens the Launcher by touching the icon at the bottom of the Home screen.
Hide app's icon using below code: PackageManager p = getPackageManager(); ComponentName componentName = new ComponentName(this, com. apps. MainActivity.
try this :
1 . Modify your MainActivity section in AndroidManifest.xml, delete from it, line with MAIN category in intent-filter section
<category android:name="android.intent.category.LAUNCHER" />//DELETE THIS LINE
Create <activity-alias>
for your app, for each of your icons. Like this
<activity-alias android:label="@string/app_name"
android:icon="@drawable/icon"
android:name=".MainActivity"
android:enabled="false"
android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
Set programmatically enabled or disabled
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With