I am trying to change the icon and label of my application after installing it.
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 PreferenceActivity, I turn on / off 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 alias activated.
As soon as this is changed, I can see on the application launchpad that the old application icon / shortcut has disappeared and on some devices it takes several times (this can take a very long time) for the launcher to display activated. During this time, it is impossible to start the application, since there is no icon.
Is there any way to update the launcher programmatically?
In addition, I tried to create a shortcut after activating / deactivating aliases. It works fine, but if I try to move the shortcut around, as soon as I release the shortcut to its new position, the Android launcher starts. 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);
Did I miss something?
EDIT . To be clear, I do not want to change the name of my application before installing it. I want to do this as soon as the application is installed on my phone.
I want to enable users to have another icon / shortcut after installing my application. If they do not activate this option, they must have the original badge / label.
I also do not want to change the name of the application with the update.