We are trying to change app icon. According to resources we use code as below. if we run this code when app is runtime then it kill the app. PackageManager.DONT_KILL_APP does not work. Is there way to change app icon without killig app ?
private fun creteComponentName(context: Context, aliasName: String): ComponentName {
return ComponentName(context, pkg + aliasName)
}
private fun enableIcon(
context: Context,
aliasName: String
){
context.packageManager.setComponentEnabledSetting(
creteComponentName(context, aliasName),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP)
}
private fun disableIcon(
context: Context,
aliasName: String
){
context.packageManager.setComponentEnabledSetting(
creteComponentName(context, aliasName),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP)
}
Manifest
<activity
android:name=".MainActivity"
android:exported="true" />
<activity-alias
android:name="StageOneLauncherAlias"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:label="@string/app_name"
android:targetActivity=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity-alias
android:name="StageSecondLauncherAlias"
android:enabled="false"
android:icon="@mipmap/ic_launcher2"
android:roundIcon="@mipmap/ic_launcher_round2"
android:label="@string/app_name"
android:targetActivity=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>