20

I need to hide or show my app's icon in the launcher depending on some runtime information. I'd like to still be able to run the activity by an explicit intent, so disabling the activity isn't a good option (I don't even know for sure if it will work, I haven't tried it yet, but I guess it will). So, can I disable an intent filter?

lapis
  • 6,872
  • 4
  • 35
  • 40
  • Answer is here, http://stackoverflow.com/questions/40505357/disable-the-intent-filter-from-android-manifest-programatically/40505924#40505924 – Takermania Nov 09 '16 at 11:30

1 Answers1

38

You can't do this directly, but you can create an activity alias in your AndroidManifest.xml with the intent filter in question, and then enable or disable the alias using PackageManager#setComponentEnabledSetting(), leaving your other intent filters in the main copy of the Activity so they won't be affected.

Community
  • 1
  • 1
mlc
  • 1,668
  • 2
  • 16
  • 30
  • 4
    Following up from [this post](http://stackoverflow.com/questions/23919329/android-how-to-create-componentname-in-code-using-activity-alias) the component name for your activity-alias will be `new ComponentName($packageName, $packageName + "." + $aliasName)` where $packageName is your app's package (get it through `getActvitiy().getPackageName()`). – Matthias Wenz Nov 12 '14 at 10:26
  • 2
    if you're using a modern version of the android gradle plugin, you can also get your package name from `BuildConfig.APPLICATION_ID`, (or `BuildConfig.PACKAGE_NAME` on slightly older versions of the plugin). This avoids doing runtime calls for in order to get what is always going to be the same string. – mlc Nov 14 '14 at 17:06
  • can i remove multiple intent ? if my activity have multiple intent for different type of NFC tags and at some point i don't want my app to detect NFC tags, so is it possible for me to remove multiple intent problematically? – Query Mar 17 '15 at 03:57