Android how to programmatically hide launcher icon

前端 未结 5 1756
孤独总比滥情好
孤独总比滥情好 2020-11-28 21:22

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

5条回答
  •  时光取名叫无心
    2020-11-28 21:58

    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

    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);
    

提交回复
热议问题