Android how to programmatically hide launcher icon

前端 未结 5 1738
孤独总比滥情好
孤独总比滥情好 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:41

    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 ?

    0 讨论(0)
  • 2020-11-28 21:55

    Hide app icon using this 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);
    

    and bring it back, with this:

    PackageManager p = getPackageManager();
    ComponentName componentName = new ComponentName(this, com.apps.MainActivity.class);
    p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    

    NOTE: This will not work for Android 10

    0 讨论(0)
  • 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 <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);
    
    0 讨论(0)
  • 2020-11-28 22:00
    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.

    0 讨论(0)
  • 2020-11-28 22:04

    With Android Q (API 29) Google changed the Launcher icon visibility behaviour. Even if you disable your Launcher Activity or completely remove the android.intent.category.LAUNCHER <intent-filter> from all your Activities, the app will appear in the launcher and open the Android OS app settings, with the exception of:

    • Packages that don't declare any permissions in their respective manifest files
    • System apps
    • Apps that don't contain any components inside their respective manifest's tag
    0 讨论(0)
提交回复
热议问题