Android how to programmatically hide launcher icon

2019-01-07 04:27发布

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 similar applications - they can remove their own icons from the launcher app list. How can I achieve the same results? Thank you.

3条回答
beautiful°
2楼-- · 2019-01-07 04:55

You can have an app without a launcher by NOT including an intent filter with MAIN and LAUNCHER in the declaration of the Activity in the AndroidManifest - the question then becomes how to do the first kick off.. Widget maybe ?

查看更多
手持菜刀,她持情操
3楼-- · 2019-01-07 05:01
PackageManager p = getPackageManager();
p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

Note that the icon may not be gone until the next reboot.

查看更多
仙女界的扛把子
4楼-- · 2019-01-07 05:10

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 <category android:name="android.intent.category.LAUNCHER" />

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);
查看更多
登录 后发表回答