twiceyuan
1/28/2016 - 8:34 AM

How to change an application icon programmatically in Android

How to change an application icon programmatically in Android

//here is superuser.apk code

        <activity android:theme="@style/Theme.Sherlock.Light" android:label="@string/app_name" android:icon="@drawable/transparent" android:name=".MainActivity" android:exported="true" android:excludeFromRecents="true" android:launchMode="singleTask" android:configChanges="locale|keyboard|keyboardHidden|orientation|screenLayout" android:noHistory="false" android:hardwareAccelerated="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        <activity-alias android:label="@string/app_name" android:icon="@drawable/ic_launcher_emblem" android:name=".MainActivity-Emblem" android:enabled="true" android:targetActivity=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity-alias>
        <activity-alias android:label="@string/app_name" android:icon="@drawable/ic_launcher_superandy" android:name=".MainActivity-SuperAndy" 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>
        <activity-alias android:label="@string/app_name" android:icon="@drawable/ic_launcher_original" android:name=".MainActivity-Original" 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>
        <activity-alias android:label="@string/app_name" android:icon="@drawable/ic_launcher_chip" android:name=".MainActivity-Chip" 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>
        <activity-alias android:label="@string/app_name" android:icon="@drawable/ic_launcher_supersu" android:name=".MainActivity-SuperSU" 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>
getPackageManager().setComponentEnabledSetting(
        new ComponentName("ru.quickmessage.pa", "ru.quickmessage.pa.MainActivity-Red"), 
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

//不显示icon的代码如下
getPackageManager().setComponentEnabledSetting(
        getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
//1 . Modify your MainActivity section in AndroidManifest.xml, delete from it, line with MAIN category in intent-//filter section

<activity android:name="ru.quickmessage.pa.MainActivity"
    android:configChanges="keyboardHidden|orientation"
    android:screenOrientation="portrait"
    android:label="@string/app_name"
    android:theme="@style/CustomTheme"
    android:launchMode="singleTask">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />//DELETE THIS LINE
    </intent-filter>
</activity>

<activity-alias android:label="@string/app_name" 
    android:icon="@drawable/icon" 
    android:name=".MainActivity-Red"
    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>