Is it possible to make an extension to change app icon

dynamically from blocks using rush or fast
PS: Sorry I posted in the wrong category 1 min back

Not possible

but why

See this

Where do you get the second icon? AppInventor only creates one icon, and extensions can't add xml resources.

But you can fork the open source ai2, add new features to AppInventor, run it locally, and build the apps you want.

1 Like

There’s an alternative solution:

Simply set a different icon in the Kodular app settings.
Build an .apk file.
Upload it to a drive.
Reset the default icon in your app.
Make sure your APK with a modified icon is downloaded from a URL.
After downloading, prompt the user to update the app, and therefore the icon.

It’s not the best solution, but it’s all I can offer.

Some time has passed, and I think it's now possible. It needs to be tested. But you'll have to compile such an extension with custom icons yourself.

2 Likes

I have the same question and issue can any one help in this?

It is not possible
It is now possible, see @Patryk_F 's answer below

As workaround you can follow the suggestion from @garte5484 Is it possible to make an extension to change app icon - #6 by garte5484
or create a shortcut icon as shown here App icon change Dynamically - Discuss - Kodular Community

Taifun

I've tested this. However, it's not possible at the moment. There's no way to add <activity-alias> to the AndroidManifest. This function needs to be added.

Now Fast has been updated. So we can change icons dynamically:

How to do it?
The easiest way to use Fast.

  1. We add our icons to AndroidManifest using <activity-alias>:
<application>
    <!-- You can use any manifest tag that goes inside the <application> tag -->
    <!-- <service android:name="com.example.MyService"> ... </service> -->
    <activity-alias android:name=".Icon1"
      android:enabled="false"
      android:icon="@drawable/icon1"
      android:targetActivity=".Screen1">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity-alias>
    <activity-alias android:name=".Icon2"
      android:enabled="false"
      android:icon="@drawable/icon2"
      android:targetActivity=".Screen1">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity-alias>
  </application>

Next, we create the code to change the icons:

  @SimpleFunction(description = "")
  public void ChangeIcon(int icon) {
    PackageManager pm = form.$context().getPackageManager();
    String pkg = form.$context().getPackageName();
    ComponentName icon1 = new ComponentName(form.$context(), pkg + ".Icon1");
    ComponentName icon2 = new ComponentName(form.$context(), pkg + ".Icon2");
    ComponentName defaultIcon = new ComponentName(form.$context(), pkg + ".Screen1");
    if(icon == 1) {
      pm.setComponentEnabledSetting(icon1, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
      pm.setComponentEnabledSetting(icon2, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
      pm.setComponentEnabledSetting(defaultIcon, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    } else if(icon == 2) {
      pm.setComponentEnabledSetting(icon1, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
      pm.setComponentEnabledSetting(icon2, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
      pm.setComponentEnabledSetting(defaultIcon, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    } else if(icon == 3) {
      pm.setComponentEnabledSetting(icon1, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
      pm.setComponentEnabledSetting(icon2, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
      pm.setComponentEnabledSetting(defaultIcon, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    }
  }

We still need to add our icons to the project. To do this, we need to create our own aar library, which we place in the deps folder. It must contain three elements:

  1. A res/drawable folder with our icons.
  2. An AndroidManifest with any package name we choose.
  3. An R.txt file with the names of our icons.

Below is an example library; the txt extension needs to be removed.

my-icons.aar.txt (20.0 KB)

In the fast.yml file we add our library:

dependencies:
- my-icons.aar:aar
7 Likes

This version of the video should also work on desktop/PC.

1 Like