react-native-change-icon icon indicating copy to clipboard operation
react-native-change-icon copied to clipboard

[Android] Changing the app icon will shut down the process. (v5.0.0)

Open Jongkeun opened this issue 10 months ago • 15 comments

Platform

  • [ ] iOS
  • [x] Android

Description This is such an obvious error. Changing the app icon on Android will shut down the process. I made a new project and tried it. But it was the same Please share the sample project repository that the app icon changes normally

To Reproduce Steps to reproduce the behavior:

  1. Install this library and follow the steps that is on How to Use
  2. call changeIcon on Android.

Expected behavior The app will not shut down and only the icon will change.

Screenshots Don't have to attach this.

Device (please complete the following information):

  • Device: zFlip 4, galxay note 10, a50
  • OS: Android 14, 13, 12

Versions

  • react-native: 0.73.2, 0.71.8
  • react-native-change-icon: 5.0.0

Code Snippet

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.appname">
  <uses-permission android:name="android.permission.INTERNET"/>
  <application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme">
    <activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:exported="true">
      <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:scheme="appname"/>
      </intent-filter>
    </activity>

      <activity-alias
            android:name="MainActivityDefault"
            android:enabled="true"
            android:exported="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="MainActivityDark"
            android:enabled="false"
            android:exported="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>
  </application>
</manifest>

Jongkeun avatar Apr 17 '24 10:04 Jongkeun

I also have the same problem, any solution?

TierryBr avatar Apr 21 '24 00:04 TierryBr

Same here.

psjostrom avatar May 06 '24 12:05 psjostrom

It's the only way to change app icon for Android. For instance check out the duckduckgo app.

Best thing you can do is to warn the user about what is about to happen.

jacobmolby avatar May 06 '24 12:05 jacobmolby

It's the only way to change app icon for Android. For instance check out the duckduckgo app.

Best thing you can do is to warn the user about what is about to happen.

@jacobmolby , you can check this feature at Todoist. It looks like there are some workaround way. They are doing without closing.

Jongkeun avatar May 07 '24 01:05 Jongkeun

It's the only way to change app icon for Android. For instance check out the duckduckgo app. Best thing you can do is to warn the user about what is about to happen.

@jacobmolby , you can check this feature at Todoist. It looks like there are some workaround way. They are doing without closing.

Interesting. So I've tried. In their implementation, you have to restart the app "to enable icon switching" but after that it works without closing.

I found this repo trying to implement something similar, but I haven't tried it out. https://github.com/gonodono/app-icon-change-demo.

jacobmolby avatar May 07 '24 08:05 jacobmolby

Has anyone found a solution for this?

RahSolteo avatar May 29 '24 10:05 RahSolteo

The best way I found was to patch ChangeIconModule, after activity.finish(); in the changeIcon method, creating a new Intent:

Intent newIconIntent = Intent.makeMainActivity(new ComponentName(this.packageName, activeClass));
newIconIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.reactContext.startActivity(newIconIntent);

This will swiftly open the new activity after the old one ends. You'll also need to store the react context in the constructor:

public class ChangeIconModule extends ReactContextBaseJavaModule implements Application.ActivityLifecycleCallbacks {
    //[...]
    private ReactApplicationContext reactContext;
    //[...]
    public ChangeIconModule(ReactApplicationContext reactContext, String packageName) {
        //[...]
        this.reactContext = reactContext;
    }
}

dylmye avatar May 30 '24 16:05 dylmye

continues... When we change the icon on Android, the application closes. Can you get your hands on it as soon as possible?

berkaygurcan avatar Jul 09 '24 05:07 berkaygurcan