简体   繁体   中英

How to change the app tray icon in android programmatically?

I had changed the app icon and app name dynamically. But the app launching icon is not changed after the app icon and app name change. Please guide.

I switched the app icon and name using activity alias concept. See image for issue: issue image

Code:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.batpoc">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
     calls FlutterMain.startInitialization(this); in its onCreate method.
     In most cases, you can leave this as-is, but you if you want to provide
     additional functionality it is fine to subclass or reimplement
     FlutterApplication and put your custom class here. -->
<application
    android:name="io.flutter.app.FlutterApplication"
    android:label="bat poc"
    android:icon="@mipmap/ic_launcher">
    <activity
        android:name=".MainActivity"
        android:launchMode="singleTop"              
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">
          <intent-filter>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

    <activity-alias
            android:label="bat poc"
            android:name=".MainActivityDefault"
            android:enabled="true"
            android:icon="@mipmap/ic_launcher"            
            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:name=".MainActivityOneLaunch"
            android:enabled="false"
            android:logo="@mipmap/th"
            android:label="One Launch"
            android:icon="@mipmap/th"            
            android:targetActivity=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity-alias>

</application>

I think that's the phone's issue. The phone might have stored some cache files of the app and hence the icon is not changed. Just clear the data of the app, then uninstall it, then reboot your phone and then build the app again.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM