Android : Change App Label programmatically

后端 未结 8 1861
轻奢々
轻奢々 2020-11-28 11:27

How can I change application label to change app name shown from java code in android? I\'m refering to:



        
相关标签:
8条回答
  • 2020-11-28 11:58

    Using <activity-alias> you can change App icon and name to few predefined by you.

    Create such config in Mannifest.xml

    <activity android:name="package.name.MainActivity"
     android:screenOrientation="portrait"
     android:label="@string/app_name"
     android:theme="@style/CustomTheme"
     android:launchMode="singleTask">
      <intent-filter>
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    
    <activity-alias android:label="@string/app_name_default" 
     android:icon="@drawable/icon_default" 
     android:name=".MainActivity-Default"
     android:enabled="true"
     android:targetActivity=".MainActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>   
    </activity-alias>
    
    <activity-alias android:label="@string/app_name_flavor_one" 
     android:icon="@drawable/icon_flavor_one" 
     android:name=".MainActivity-Flavor-One"
     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>
    

    Now you can switch between those two aliases, therefore we will change app icon or/and name. To switch from Default to Flavor-One use this code.

     getPackageManager().setComponentEnabledSetting(
        new ComponentName("package.name", "package.name.MainActivity-Flavor-One"), 
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
     getPackageManager().setComponentEnabledSetting(
        new ComponentName("package.name", "package.name.MainActivity-Default"), 
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    

    Keep in mind that you have to track that only one alias will be enabled at a time

    0 讨论(0)
  • 2020-11-28 11:58

    If you are extending the firmware, you can actually accomplish this by changing IconCache.java file and make it show a string with some internal value of the phone.

    For example if you want the SIM Toolkit to show the name of the carrier, you can do that this way.

    But for regular apps, as it's been said, it's currently not posible.

    0 讨论(0)
提交回复
热议问题