How to change the icon and label of the application after installing it?

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.

+4
source share
3 answers

The code posted in the question is apparently the correct way. There is a problem with Android 4.1 and 4.2. More details here:

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

+1
source

I think I can help you. The manifest tag has the following:

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

You can edit them and change to the icon that you saved in your drawings for your launcher, and you can also change their name to another line.

0
source

To change the name of the application, right-click the application folder in the package explorer, find "Refactoring" and click "Rename".

To change the application icon, you must change all its options inside the drop-down folders, as well as "ic_launcher-web.png" inside the res folder.

-one
source

Source: https://habr.com/ru/post/1015042/


All Articles