Change app icon programmatically in react-native. How can I modify the app icon on the clicking of button in react-native ( iOS and android each )

[ad_1]

How can I modify the app icon on the clicking of button in react-native ( iOS and android each )

@ReactMethod
public void setDefaultIcon(Promise promise) {
String defaultPackageName = "NOT_FOUND";
attempt {
WritableMap map = Arguments.createMap();
defaultPackageName = appContext.getPackageName() + ".MainActivity";
String newPackageName = defaultPackageName + "Alias";
// allow outdated icon
PackageManager supervisor = appContext.getPackageManager();
supervisor.setComponentEnabledSetting(new ComponentName(appContext, "com.pattern.MainActivity"),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

        // disable new icon
        supervisor.setComponentEnabledSetting(
                new ComponentName(appContext, "com.pattern.MainActivityAlias"),
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
        map.putString("successMsg", "Icon modified to default efficiently");
        promise.resolve(map);
    } catch (Exception e) {
        e.printStackTrace();
        promise.reject("EXCEPTION", e);
    }
}

@ReactMethod
public void setNewIcon(Promise promise) {
    String defaultPackageName = "NOT_FOUND";
    attempt {
        WritableMap map = Arguments.createMap();
        defaultPackageName = appContext.getPackageName() + ".MainActivity";
        String newPackageName = defaultPackageName + "Alias";
        // disable outdated icon
        PackageManager supervisor = appContext.getPackageManager();
        supervisor.setComponentEnabledSetting(new ComponentName(appContext, "com.pattern.MainActivity"),
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

        // allow new icon
        supervisor.setComponentEnabledSetting(
                new ComponentName(appContext, "com.pattern.MainActivityAlias"),
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
        map.putString("successMsg", "Icon modified efficiently");
        promise.resolve(map);
    } catch (Exception e) {
        e.printStackTrace();
        promise.reject("EXCEPTION", e);
    }
}

<activity-alias
android:title="com.pattern.MainActivityAlias"
android:enabled="false"
android:exported="true"
android:icon="@mipmap/newlogo"
android:roundIcon="@mipmap/newlogo"
android:targetActivity=".MainActivity"
>
<intent-filter>
<motion android:title="android.intent.motion.MAIN" />
<class android:title="android.intent.class.LAUNCHER" />
</intent-filter>
</activity-alias>

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *