/**<activity-alias android:name=".icon_tag" android:enabled="true" android:icon="@mipmap/about_logo" android:label="@string/app_name" android:targetActivity=".activity.SplashActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity-alias> <activity-alias android:name=".icon_tag_1212" android:enabled="false" android:icon="@mipmap/icon_festival" android:label="@string/app_name" android:targetActivity=".activity.SplashActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity-alias>
* 显示假日
*
* @param useCode 1、为活动图标 2 为用普通图标 3、不启用判断
*/
public static void switchIcon(Context context, int useCode) {
String pkName = context.getPackageName() + "." + spFileName;
try {
//要跟manifest的activity-alias 的name保持一致
String icon_tag = "com.example.administrator.huijianzhi.icon_tag";
String icon_tag_1212 = "com.example.administrator.huijianzhi.icon_tag_1212";
if (useCode != 3) {
PackageManager pm = context.getPackageManager();
ComponentName normalComponentName = new ComponentName(context, icon_tag);
//正常图标新状态,此处使用用来修改清单文件中activity-alias下的android:enable的值
int normalNewState = useCode == 2 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
: PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
//新状态跟当前状态不一样才执行
if (pm.getComponentEnabledSetting(normalComponentName) != normalNewState) {
//PackageManager.DONT_KILL_APP表示执行此方法时不杀死当前的APP进程
pm.setComponentEnabledSetting(normalComponentName, normalNewState, PackageManager.DONT_KILL_APP);
}
ComponentName actComponentName = new ComponentName(context, icon_tag_1212);
//活动图标新状态
int actNewState = useCode == 1 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
//新状态跟当前状态不一样才执行
if (pm.getComponentEnabledSetting(actComponentName) != actNewState) {
pm.setComponentEnabledSetting(actComponentName, actNewState, PackageManager.DONT_KILL_APP);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
SpUtils.switchIcon(mContext, 1);//icon_tag_1212
<activity-alias
android:name=".icon_tag"
android:enabled="true"
android:icon="@mipmap/about_logo"
android:label="@string/app_name"
android:targetActivity=".activity.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity-alias
android:name=".icon_tag_1212"
android:enabled="false"
android:icon="@mipmap/icon_festival"
android:label="@string/app_name"
android:targetActivity=".activity.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>