Updated 11 October 2021
Change Launcher icon dynamically in Android! What is it mean? Well, let’s discuss it. In the mobile application, we can say the launcher icon is the unique identification of that app. The launcher icon is self-sufficient to define the type of application. Normally a single app consists of a single launcher icon. But how we will manage, when we have to change or update the launcher icon on runtime according to different scenarios. Or when we try to change the launcher icon dynamically.
In this blog, we will learn how we can change or update the launcher icon dynamically or on runtime. For this, we will follow the mentioned steps:
In this step, we will create an empty class for each launcher icon that we want to change on runtime. This is class is an empty class, which consists of nothing in its body. I have created two empty classes for the two launcher icon, you can create any number of them as per the requirement.
1 2 3 |
class FirstLauncherAlias { } |
1 2 3 |
class SecondLauncherIcon { } |
1 2 3 4 5 6 7 8 9 10 11 |
<activity-alias android:name="FirstLauncherAlias" android:enabled="true" android:icon="@mipmap/ic_launcher1" android:label="@string/app_name" android:targetActivity=".activities.SplashScreenActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity-alias> |
1 2 3 4 5 6 7 8 9 10 11 12 |
<activity-alias android:name="SecondLauncherAlias" android:enabled="false" android:icon="@mipmap/ic_launcher1" android:label="@string/app_name" android:targetActivity=".activities.SplashScreenActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity-alias> |
After all the steps, we can now enable or disable the activity alias according to your requirement. In this demo, we are performing on the splash screen launching, with the help of shared pref. You can do it on this button click event or any other event.
1 2 3 |
packageManager.setComponentEnabledSetting(ComponentName(this@SplashScreenActivity, FirstLauncherAlias::class.java), PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP) packageManager.setComponentEnabledSetting(ComponentName(this@SplashScreenActivity, SecondLauncherAlias::class.java), PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP) |
1 2 3 |
packageManager.setComponentEnabledSetting(ComponentName(this@SplashScreenActivity, SecondLauncherIcon::class.java), PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP) packageManager.setComponentEnabledSetting(ComponentName(this@SplashScreenActivity, FirstLauncherAlias::class.java), PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP) |
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.