How to create/disable intent-filter programmatically?

后端 未结 3 1888
死守一世寂寞
死守一世寂寞 2020-12-05 20:35

I have three activity and three Intent Filters for them in the Android Manifest.



        
相关标签:
3条回答
  • 2020-12-05 20:41

    An intent filter is an instance of the IntentFilter class. However, since the Android system must know about the capabilities of a component before it can launch that component, intent filters are generally not set up in Java code, but in the application's manifest file (AndroidManifest.xml) as elements. (The one exception would be filters for broadcast receivers that are registered dynamically by calling Context.registerReceiver(); they are directly created as IntentFilter objects.)

    source: http://developer.android.com/guide/components/intents-filters.html

    Also, see this: https://stackoverflow.com/a/10403074/832776

    0 讨论(0)
  • 2020-12-05 20:42

    If your Activity had multiple intent-filters then you could disable a specific intent-filter by creating an activity-alias with the intent-filter you want to disable and disable just the Activity alias. See: https://developer.android.com/guide/topics/manifest/activity-alias-element.html

    0 讨论(0)
  • 2020-12-05 20:59

    You can neither enable, disable, or create <intent-filter>s programmatically.

    However, in your case, you only have one <intent-filter> per component. In that case, you can enable and disable the component programmatically, via PackageManager and setComponentEnabledSetting(). In your case, enabling or disabling the activity would have the same basic effect as enabling or disabling its <intent-filter>.

    0 讨论(0)
提交回复
热议问题