4

At Instagrams anniversary the users were possible to change the app icon. Even though this feature isn't available anymore Todoist has a similar working implementation of this feature.

I researched how to achieve this and got the second answer running: change application icon.

But this solution seems to come with drawbacks which I don't want. Some of these are listed here under the notes: blog change app icon. Furthermore, by using this solution my App gets killed every time I choose another icon with the activity-alias and I wasn't able to keep the app alive.

The behaviour of the Todoist App: First you have to activate the "change app icon dynamically"-feature which closes the app. Then after starting the app again the feature is available and you can change the app icon as you want.

As far as I know Instagrams implementation didn't even need this little restart, but I would be okay with that because this solution would be better than the one existing right now.

So how does the Todoist or Instagram approach work and how would an implementation look like?

Tobi B.
  • 65
  • 7
  • AFAICT, Todoist is using that same basic technique. They've got about 30 different `` entries in [their current manifest](https://drive.google.com/file/d/1TdclN4Eow8kg4h2uiHZuGfuh6TNNICCb/view?usp=sharing). I'm not yet sure how to explain the activation sequence, though. Indeed, after the first activation and restart, it never asks to do that again, which makes one wonder why it's not just set up like that from the start. – Mike M. Jul 31 '21 at 17:22
  • 1
    Yes this was also really weird to me. So the killing of the App seems to be necessary one time but then the question is why it is not necessary anymore for the next changes and what they have done to prevent the killing then. – Tobi B. Aug 02 '21 at 10:11
  • 2
    In poking around their code, my first thought is that perhaps there is some subtle difference in behavior when using `setComponentEnabledSetting()` with `COMPONENT_ENABLED_STATE_DISABLED` versus `COMPONENT_ENABLED_STATE_DEFAULT`, as they only use `COMPONENT_ENABLED_STATE_DISABLED` with the default ``, `HomeActivityDefault`; i.e., the only one that doesn't have `android:enabled="false"` set. The rest of them are set to `COMPONENT_ENABLED_STATE_DEFAULT`. Also, one of those other `` entries – `HomeActivityTodoist` – is the same as the default, so maybe after... – Mike M. Aug 02 '21 at 16:34
  • 2
    ...the initial `DISABLED` setting on the default alias, the rest of the changes are just `ENABLED` or `DEFAULT` between the rest of the ``es, which might not force a restart. That's all purely conjecture at this point, as I can't test anything atm. – Mike M. Aug 02 '21 at 16:34
  • Wow didn't expect to get a solution from you this quick. Thank you so much for testing this out and giving me/us a good example on how to implement such behaviour. Besides this will be a workaround for now as android isn't officially supporting this feature yet, do you know about the drawbacks of this implementation? I read about loosing the ability to update the app when a different alias is activated. Will this really not work? And if yes is there any other workaround as switching the icon/activity-alias back before the update? – Tobi B. Aug 04 '21 at 07:42
  • No problem. I just happened to be setting up a new dev machine while I was investigating this, so I used the opportunity to test the Git/GitHub setup. Sorry the code's kind of a mess; it was late. Anyhoo, as far as I'm aware, the only main issue to upgrading is that you can't ever change the class names for your aliases, or remove any of them altogether. Apart from that, I _think_ it's basically just the occasional issue with launching; e.g., the user's launcher isn't going to update immediately so they might get "App not installed" until it does, the launcher icons might simply be removed... – Mike M. Aug 04 '21 at 14:10
  • ...instead of updated, also Android Studio will try to launch the wrong thing if you're updating a debug install that has a new alias set, etc. You should always be able to launch it from the app drawer, or whatever the main app list is in your launcher. I'm not 100% certain of all that, though; I've never released an app with this functionality. I did include a reset button in the demo, however, to at least show how that could work, and to make it a little easier during testing and debugging (provided that you can remember to reset before pushing a build that requires a fresh install :-). – Mike M. Aug 04 '21 at 14:10
  • 1
    Alright so all this has to be tested out on a production app with updates. I will post here again when I tried it out and tell about my observations. But don't expect that to be in the near future because I never released any app before :D Thanks for all your efforts! Hopefully someday android will make it easier for us - just like iOS – Tobi B. Aug 04 '21 at 15:15
  • yes no problem :) – Tobi B. Aug 05 '21 at 15:17
  • 1
    I finally cleaned up that demo a bit, so I'll leave the link again, in case it might be of help to others: https://github.com/gonodono/app-icon-change-demo. Cheers! – Mike M. Sep 26 '21 at 18:29
  • thanks for that extra work. really appreciate it :) – Tobi B. Oct 04 '21 at 15:40
  • 2
    @MikeM. that was good observation about COMPONENT_ENABLED_STATE_DEFAULT – Jemshit Feb 28 '22 at 10:48
  • Also i found this for Google Calendar app: https://www.codeproject.com/Articles/5269715/Dynamically-Changing-Android-App-Icons-For-the-Res Launchers do treat them specially. I tried installing GoogleCalendar app on phone with PlayServices and without: right after installation app icon was showing the day of month. Then i disabled custom MicrosoftLauncher and custom app icon was gone – Jemshit Mar 04 '22 at 11:40
  • 1
    For instagram case, it was Shortcut on android, not app icon itself: https://www.youtube.com/watch?v=tzWdVyQP1oE – Jemshit Mar 04 '22 at 12:01

0 Answers0