3

I noticed that on a Xiaomi Mi Phone icons are iOS'ed. This is why the icon for an app that I am working on looks terrible.

Is there a way to provide a separate icon just for those Xiaomi Mi Phones? Or is this the user would have to change himself?

Skizo-ozᴉʞS ツ
  • 19,464
  • 18
  • 81
  • 148
Georg
  • 3,664
  • 3
  • 34
  • 75
  • You should be able to get the device model by using `String device = Devices.getDeviceName();` now if it matches Xiaomi , change device icon. See [this](http://stackoverflow.com/questions/1995439/get-android-phone-model-programmatically) to know more about how to get device name. – Tushar Gogna Feb 18 '15 at 11:06

1 Answers1

0

You can check the device manufacturer and then with the help of using activity-alias for different icons you can change the icon specifically for Xiaomi phones. The process goes like this -

First under your main activity declaration in your Manifest file create 2 new Activity-Alias :

<!-- MAIN ACTIVITY -->
    <activity
        android:name="com.example.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <!-- 2 ACTIVITY ALIAS For Main Activity -->
    <activity-alias
        android:name="com.example.MainActivity-Normal"
        android:enabled="true"
        android:icon="@drawable/logo_normal"
        android:label="@string/app_name"
        android:targetActivity="com.example.MainActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity-alias>

    <activity-alias
        android:name="com.example.MainActivity-Xiaomi"
        android:enabled="false"
        android:icon="@drawable/logo_xiaomi"
        android:label="@string/app_name"
        android:targetActivity="com.example.MainActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity-alias>

Notice that i have removed the line

<action android:name="android.intent.action.MAIN" />

from the MainActivity declaration. Its only there in Activity-Alias. Also only the first Activity-Alias is enabled which is for the normal icon and the second Activity-Alias with Xiaomi icons is disabled initially.

Now the second step, open your MainActivity.java and inside it make this method :

private void checkForIcon(){
    if(Build.MANUFACTURER.equals("Xiaomi")){
        getPackageManager().setComponentEnabledSetting(
                new ComponentName("com.example", "com.example.MainActivity-Normal"), 
                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
        getPackageManager().setComponentEnabledSetting(
                new ComponentName("com.example", "com.example.MainActivity-Xiaomi"),
                    PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    }
}

After this simply call this method in your MainActivity's OnCreate() method and you're done.

As soon as the app launches the first time it will check whether the phone is manufactured by Xiaomi and if it is then it will use the second Activity-Alias by enabling it and disabling the first one(So that 2 icons don't show up in your phone).

Make sure you put the correct package name everywhere and put both sets of app icons in your drawable folder with the name specified in Manifest file.

Jyotman Singh
  • 10,792
  • 8
  • 39
  • 55