skb1129 / react-native-change-icon

Change your application icon programmatically for React Native apps
MIT License
500 stars 92 forks source link

this.componentClass.split("MainActivity")[1] does not exist #69

Closed nicolasdevienne closed 2 years ago

nicolasdevienne commented 2 years ago

Platform

Description I suggest you to change function getIcon() for Android :

        String currentIcon = this.componentClass.split("MainActivity")[1];
        promise.resolve(currentIcon.isEmpty() ? "default" : currentIcon);

by

        String[] currentIcon = this.componentClass.split("MainActivity");
        promise.resolve(currentIcon.length > 1 ? currentIcon[1] : "default");

Because when we launch for the first time the app, getCurrentActivity().getComponentName().getClassName() returns "com.xxx.MainActivity" and split function return an array with only one value, this.componentClass.split("MainActivity")[1] does not exist !

Versions

nicolasdevienne commented 2 years ago

This issue appears only on simulator. On real device it's OK!

Nitish33 commented 1 year ago

This issue will also occur when you open the app from App shortcut (Long press menu). Best to put a check on length instead of directly accessing it.