1

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?

Armand
  • 23,463
  • 20
  • 90
  • 119
  • what do you need that for? – pskink Jul 03 '15 at 14:25
  • 1
    stealing users' bank details – Armand Jul 03 '15 at 15:19
  • [**`ComponentName`**](http://developer.android.com/reference/android/content/ComponentName.html) can be your new `ActivityAlias` in terms of activiting – Elltz Jul 03 '15 at 15:41
  • @Elltz I'm aware that `ComponentName` can be used to refer to an `` already defined in `AndroidManifest.xml`. Are you saying that new `ActivityAlias`es can be created using `ComponentName`? – Armand Jul 03 '15 at 15:43
  • bad news, you cannot "define at runtime" any kind of `Activity` (including **AliasActivity**) – pskink Jul 03 '15 at 16:08
  • that's what I suspected :¬( Is it documented anywhere? – Armand Jul 03 '15 at 16:10
  • docs/guide/components/activities.html "Declaring the activity in the manifest You must declare your activity in the manifest file in order for it to be accessible to the system." – pskink Jul 03 '15 at 16:11
  • you can however declare your own "proxy activity" that does the similar thing but since you didnt say what it is for i cannot say anything more – pskink Jul 03 '15 at 16:15
  • @pskink proxy activity looks like it has fixed text and icon - i am hoping to rebrand my app for different businesses – Armand Jul 03 '15 at 16:39
  • it seems so, you cannot help it... – pskink Jul 03 '15 at 16:59
  • I recently had a similar problem with the activities ,practically I needed to create them dinamically.That's not possible but I found a way to deal with my problem.If you explain me what you want to achieve ,I might be able to help you out. – Vlad Jul 03 '15 at 20:15

2 Answers2

2

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.

0

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.

zmarties
  • 4,809
  • 22
  • 39
  • Hi zmarties, thanks for the considered response - I think you've identified the issues well, but misunderstood my priorities. I want to avoid having to publish new versions every time a branding is added or removed. Apart from anything else, a user of brand `A` shouldn't have to update his app just because we now support brand `X`. – Armand Jul 06 '15 at 15:26