0

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>
BRSKZR
  • 23
  • 6
  • 3
    Note that there is no guarantee that this will work without a reboot. It will depend on the launcher implementation and whether it detects this change. – CommonsWare Sep 12 '22 at 14:51
  • Yeah, that's always been hacky and unreliable, but there's some relevant info in the comments here: https://stackoverflow.com/q/68576022. – Mike M. Sep 12 '22 at 16:31

0 Answers0