I am trying to change the icon and label of my app once it is installed.
In the manifest, i put this code :
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MyTheme" >
// 1st Activity declaration
<activity
android:name=".activities.SplashScreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:theme="@style/Theme.Sherlock.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
// I removed the next line to put it with the alias :
// <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
// Activity Aliases
<activity-alias
android:name=".Alias_0"
android:enabled="true"
android:icon="@drawable/ic_launcher"
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>
<activity-alias
android:name=".Alias_1"
android:enabled="false"
android:icon="@drawable/alias1"
android:label="@string/alias1"
android:targetActivity=".activities.SplashScreenActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
And in a PreferenceActivity, I am enabling/disabling aliases like this :
packageManager.setComponentEnabledSetting(
new ComponentName("com.mypackage", "com.mypackage.Alias_0"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
packageManager.setComponentEnabledSetting(
new ComponentName("com.mypackage", "com.mypackage.Alias_1"),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
There is always only one activated alias.
Once this is changed, I can see on the application launcher that the old app icon/label has disappeared and on some devices, it takes some times (it can last very long) for the launcher to display the activated one. During this time, there is no way to launch the app since there is no icon.
Is there any way to refresh the launcher programmatically ?
Also, i've tried to create a shortcut after the activation/deactivation of the aliases. It works fine but if I try to move the shortcut around, once I release the shortcut to its new position, the Android launcher crashes. Here is the code I'm using :
Intent shortcutIntent = new Intent(getApplicationContext(), SplashScreenActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutTitle);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), shortcutDrawableId));
addIntent.putExtra("duplicate", false);
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(addIntent);
Am I missing something ?
EDIT : Just to be clear, I am not looking to change the name of my app BEFORE installing it. I want to do it once the app is installed on my phone.
I want to give the opportunity to users to have another icon/label once they have installed my app. If they don't activate that option, they should have the original icon/label.
I am also not looking to change the name of the app with an update.