How to visible/invisible launcher icon in android?

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


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

链接地址: http://www.djcxy.com/p/17396.html

上一篇: 抽象枚举的sun.reflect.Reflection处理中可能存在的错误?

下一篇: 如何在Android中可见/不可见的启动器图标?