is it possible change Application icon dynamically in android without update the application?

Viewed 76

I am trying to add different types of App icons and different App names dynamically based on different places for the same application without update!. Otherwise, I need to provide 3 different builds. I hope I am clear.

1 Answers

Go to your AndroidManifest.xml file and add this code

<application 
  android:theme="@style/Theme.packagename"
  android:supportsRtl="true" 
  android:roundIcon="@mipmap/ic_launcher_round"
  android:label="@string/app_name" 
  android:icon="@mipmap/ic_launcher_first"
  android:allowBackup="true">

<activity android:name=".MainActivity">

...
</activity>

<!-- second icon -->
<activity-alias 
  android:name=".MainActivityAlias" 
  android:roundIcon="@drawable/ic_launcher_p_foreground"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher_second"
  android:enabled="false" 
  android:targetActivity=".MainActivity">
  
    <intent-filter>
  
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
  
    </intent-filter>
  
  </activity-alias>
</application>

this is a function to change the first icon into the second icon

private void changeIconToSecond() {
        // disables the first icon
        PackageManager packageManager = getPackageManager();
        packageManager.setComponentEnabledSetting(new ComponentName(MainActivity.this, "com.radefffactory.appiconchange.MainActivity"),
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);

        // enables the second icon
        packageManager.setComponentEnabledSetting(new ComponentName(MainActivity.this, "com.radefffactory.appiconchange.MainActivityAlias"),
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);
    }

To return to the first icon

private void changeIconTOFirst() {
        // disables the second icon
        PackageManager packageManager = getPackageManager();
        packageManager.setComponentEnabledSetting(new ComponentName(MainActivity.this, "com.radefffactory.appiconchange.MainActivity"),
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);

        // enables the first icon
        packageManager.setComponentEnabledSetting(new ComponentName(MainActivity.this, "com.radefffactory.appiconchange.MainActivityAlias"),
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
    }
Related