In my app I want to change the icon of the app based on the notification received. i.e if there are 2 notifications received, then the app icon having "2" in it will be shown in home screen of the device.
For this I have used activity alias. I have added following intent filters for the activity alias:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
And to make a activity-alias active I have used following code:
This is to enable the activity alias:
ComponentName componentName = new ComponentName("PACKAGE_NAME_HERE",
lastEnabled);
pm.setComponentEnabledSetting(componentName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
Utility.setLastEnabled(lastEnabled,context);
This will disable previously enabled activity alias
componentName = new ComponentName(
"PACKAGE_NAME_HERE", prevLastEnabled);
pm.setComponentEnabledSetting(componentName,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
But as soon the app icon changes, my app closes without any exception. I have used dont kill app here, still it closes the app. Can anyone please suggest me if I am doing anything wrong.Thanks.