Dynamic AndroidManifest.xml

2019-05-07 21:35发布

问题:

Is it possible to dynamically define aspects of the AndroidManifest.xml? For example, is it possible to register or edit the definition of activities, services and receivers on the fly, using Java code?

If so, are there any limitations on where this code should be placed? What else can be dynamically defined?

回答1:

I believe most of the available operations are described by the PackageManager documentation

You can add and remove permissions (addPermission()) and you can enable or disable components (services, receivers etc.) with setComponentEnabledSetting().