android实现动态更换应用图标

  • 1、配置activity别名

android:enabled 属性,布尔类型,是否开启别名设置,默认值为 true;
android:exported 属性,布尔类型,是否支持其他应用通过这个别名访问目标 Activity,默认值为 true;

        
            
                
                
            
        
        
            
                
                
            
        
        
            
                
                
            
        
  • 2、执行切换逻辑

icon tag为您配置的别名路径,比如com.demo.icon_tag

 pm.setComponentEnabledSetting(getComponentName(),
                        PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
 pm.setComponentEnabledSetting(new ComponentName(this,icon_tag),
                        PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

点击后即可更换如果需要及时更换需要重启luncher activity:
private void restartApp(){
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.addCategory(Intent.CATEGORY_DEFAULT);
List resolves = pm.queryIntentActivities(intent, 0);
for (ResolveInfo res : resolves) {
if (res.activityInfo != null) {
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
am.killBackgroundProcesses(res.activityInfo.packageName);
}
}

参考资料:http://www.jianshu.com/p/2caea5909a87

你可能感兴趣的:(android实现动态更换应用图标)