4

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.

Matthieu Coisne
  • 624
  • 1
  • 13
  • 25
  • any luck with this. as i am facing the same.. – Rohit Sharma Nov 06 '13 at 17:54
  • It's not possible n runtime. But you can provide different Shortcuts that can have any icon and label you want. Nevertheless, this will not change your icon/label in the app menu. For this, if you already know what icon/label you want, create Activity-Aliases and disable them in the beginning and enable them seperately in runtime. – JacksOnF1re Oct 29 '15 at 16:52

3 Answers3

1

The code posted in the question is apparently the correct way to do it. There is an issue with Android 4.1 and 4.2. Find more details here:

https://code.google.com/p/android/issues/detail?id=54546

Matthieu Coisne
  • 624
  • 1
  • 13
  • 25
0

I think I may be able to help you. Under the manifest tag there is this:

<application
    android:allowBackup="true"
    android:icon="@drawable/launcher_icon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" />

You can edit these and change it to the icon that you saved in your drawables for your launcher and you can also change them name to a different string.

superuser
  • 731
  • 10
  • 28
  • I already have these information added to the Application tag. As I wrote, I want to change the label/icon of my app that is already installed and visible in the Android launcher. – Matthieu Coisne Aug 01 '13 at 21:00
  • Ok.You can try to reinstall the app, and then the name and launcher will get updated. – superuser Aug 01 '13 at 21:08
  • No. 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. – Matthieu Coisne Aug 01 '13 at 21:12
-1

To change the name of your application right click the application folder in the package explorer, look for "Refactor" and press rename.

To change the icon of your application you have to change all of its variations inside the drawable folders and also the "ic_launcher-web.png" inside your res folder.

IDSA
  • 1
  • 2
  • I don't want to change the name of my application BEFORE installing it on my phone, I want to do it to my already installed app – Matthieu Coisne Aug 01 '13 at 21:04
  • You mean updating the application to a newer version? If so, then you have to change the version code in your xml. – IDSA Aug 01 '13 at 21:07
  • No. I want to give the opportunity to users to have another icon/label once they have installed my app – Matthieu Coisne Aug 01 '13 at 21:09
  • If you want different icons you can add parameters to your drawable folders. I don't believe users are able to change the name and icon of the application to appear differently on the launcher. – IDSA Aug 01 '13 at 21:12