I am trying to add different types of app icons and different 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.
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.