How to change the launcher icon and its label from the application

How can I change the launcher icon and its shortcut from my Android app? (if possible)
I mean the properties defined in AndroidManifest.xml : android:icon and android:label . I want to replace it with the image that I am taking from the camera.

+2
source share
2 answers

Edit: your original answer did not indicate that you want to do this at runtime. Below the line how to do it, before compiling. Regarding execution programmatically at runtime:

From this answer :

You cannot change a manifest or resource in an APK with a signature and a seal, with the exception of a software update.

But also, the accepted answer found out to “hack” or some kind of fraudulent way to do this (I suppose). I have not tested it, but there is a source for you.

Or, this link seems to describe how to do this using the widget approach.


So let's say your manifest was like this:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="yourPackage" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > ... 

You would change the launch icon by placing images in your patches:

 Project folder --> res --> all the drawables 

Then you must change android:icon="@drawable/ic_launcher" as android:icon="@drawable/whateverTheNameOfTheImageIsYouPutInTheDrawablesFolders"


To change the label:

Open the strings.xml file, which is located:

 Project folder --> res --> values --> strings.xml 

Look for a line that looks like this:

 <string name="app_name">Your App Name</string> 

And just change Your App Name to what you want the label to be.


Summary:

android:icon="@drawable/ic_launcher" defines your launch icon, so just add images to the drop-down folders and change ic_launcher so that the image name means you want to be an icon.

android:label="@string/app_name" defines your "label", so just find app_name (since the label refers to @string/app_name ) in your strings.xml file and change the contents of app_name .

+4
source

This whole answer is from this post and it was taken from PA and CommonsWare .


You cannot change the manifest or resource in the agro-industrial complex with signature and seal, with the exception of software updates. or try this, this works great for me, but not necessarily for all devices:

  • Change the MainActivity section in AndroidManifest.xml, delete the line with the main category in the intent filter section from it.

     <activity android:name="ru.quickmessage.pa.MainActivity" android:configChanges="keyboardHidden|orientation" android:screenOrientation="portrait" android:label="@string/app_name" android:theme="@style/CustomTheme" android:launchMode="singleTask"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />//DELETE THIS LINE </intent-filter> </activity> 
  • Create <activity-alias> for your application for each of your icons. Like this

     <activity-alias android:label="@string/app_name" android:icon="@drawable/icon" android:name=".MainActivity-Red" android:enabled="false" android:targetActivity=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity-alias> 
  • Set the software attribute ENABLE to the required

     getPackageManager().setComponentEnabledSetting( new ComponentName("ru.quickmessage.pa", "ru.quickmessage.pa.MainActivity-Red"), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); 

Note. At least one must be enabled and improved to 4.0, not tested in> 4.0.

+6
source

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


All Articles