Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
366 views
in Technique[技术] by (71.8m points)

android - How to change launcher icon and it's label from the application

How can I change the launcher icon and its label from my application runtime in Android? (if it is possible)
I mean the properties defined in AndroidManifest.xml: android:icon and android:label. I want to replace it by the image I take from the camera.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This entire answer is from this post and it was taken from P-A and CommonsWare.


You cannot change the manifest or the resource in the signed-and-sealed APK, except through a software upgrade. or Try this, it`s work fine for me but not sure for all devices:

  1. Modify your MainActivity section in AndroidManifest.xml, delete from it, line with MAIN category in intent-filter section.

    <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>
    
  2. Create <activity-alias> for your app, 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>
    
  3. Set programmatically ENABLE attribute for necessary

    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 above code perfect working up to 4.0 not tested into >4.0.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...