Is it possible to add new ActivityAliases at runtime?

138 Views Asked by At

In AndroidManifest.xml, it's possible to define multiple <activity-alias> elements. However, the ActivityAlias java class does not suggest that these aliases can be defined at runtime.

Is it possible to add new activity aliases to an app at runtime?

2

There are 2 best solutions below

1
On

From the clarification you gave in the comments, it appears that you don't actually want or need to define these aliases at runtime.

What you actually want to do is define lots of aliases (each with their own icon and text), but only have one of them active at once. When a particular user runs your app, you identify which branding they are associated with, and make just that alias active, via PackageManager.setComponentEnabledSetting. You may hit problems with some launchers that cache icons, and can get confused when the enabled activities for an app change, but any problems will just be shortlived, and generally go away next time the phone is powercycled (and thus the launcher app is restarted).

If you want to add another brand to your app, then you need to release a new version to the store with another alias in it, but that's fine, since all the users for the new brand will be coming to the app for the first time, and thus have to go to the store to install the app anyway.

0
On

You cannot add new activity alias to your app dynamically or edit the manifest file as this would be a violation of the Android security model. One purpose of the manifest file is that the developer must define which activities are part of the application and what they are allowed to do. Just read the Android documentation about signing an apps. Android apps must be signed with a private key before they can be published through Google Play. If you would be able to alter the any of the app's files within the .apk file then the signature won't be correct any more and a validation would fail.