capacitor-community / app-icon

Capacitor plugin to programmatically change the app icon.
MIT License
78 stars 19 forks source link

AppIcon.change('icon_name') returns -1 #26

Open ghonche opened 1 year ago

ghonche commented 1 year ago

Describe the bug

I'm using @capacitor-community/app-icon version 3.1.0-beta.0 in my android project. Following code returns -1 as response:

AppIcon.change({name: 'ic_launcher2', suppressNotification: true}).then(response =>{ console.log(response); });

And app icon doesn't change.

I added activity and activity-alias to AndroidManifest.xml like this:

  <activity
        android:exported="true"
        android:name="pro.lifa.app.MainActivity"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
        android:hardwareAccelerated="true"
        android:label="@string/title_activity_main"
        android:launchMode="singleTask"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBarLaunch"
        android:supportsPictureInPicture="true"
        android:windowSoftInputMode="adjustResize"
         tools:targetApi="n">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>

            <data android:host="web.lifa.pro"
                  android:scheme="https"/>

            <data android:host="web.lifa.pro"
                  android:scheme="http"/>
        </intent-filter>
    </activity>

    <activity-alias
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:name=".ic_launcher"
        android:enabled="true"
        android:exported="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="@mipmap/ic_launcher2"
        android:roundIcon="@mipmap/ic_launcher2_round"
        android:name=".ic_launcher2"
        android:enabled="false"
        android:exported="true"
        android:targetActivity=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity-alias>

Expected behavior AppIcon.change('icon_name') must change the app icon.

Screenshots Console log: Screenshot 2023-01-16 at 12 08 29 PM

Smartphone

Additional context

Any help is appreciated.

johnborges commented 1 year ago

@ghonche There are some known issues with the beta version of the plugin and certain versions of Android. I'll try making an AVD with the settings you mentioned and see if I can get anymore info on your error.