Android: Dynamically asscociating data type with a

2019-01-24 23:05发布

问题:

I have a use case in my application, where after certain point, I need to associate an data with an activity. So whenever an intent with an action and the data type is fired, my activity can be opened. I know that it is possible to associate a data type with an activity statically via AndroidManifest.xml.

Is it possible to register the data type for an activity dynamically and programatically ? Any pointers are appreciated.

回答1:

Is it possible to register the data type for an activity dynamically and programatically ?

No.

If the <intent-filter> you want is known in advance, but you only want to enable it after a certain point, you may be able to achieve this via <activity-alias> (have it disabled at the outset and enable it programmatically via PackageManager). Alas, <intent-filter> does not appear to be something you can enable or disable, at least based on what I see in the manifest documentation.