AndroidManifest.xml 中
<activity-alias android:name="包名.ui.mine.SecondActivityAlias" android:label="快捷入口" android:icon="@mipmap/collection_one" android:targetActivity="包名.ui.splash.SplashActivityZs"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity-alias> <activity-alias android:name="包名.ui.mine.SecondActivityAlias2" android:label="快捷入口2" android:icon="@mipmap/collection_two" android:targetActivity="包名.ui.splash.SplashActivityZs"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity-alias>
//注意:SecondActivityAlias SecondActivityAlias2 需要创建相应的activity 否则下面ComponentName 方法会报 找不到文件问题
/** * 下面逻辑是 将快捷入口2禁用 快捷入口开启 */ fun switchAppIcon() { val context: Application = TTWMyApplication.myApplication!! val aliasComponentName = ComponentName( applicationContext, "包名.ui.mine.SecondActivityAlias" ) val aliasComponentName2 = ComponentName( applicationContext, "包名.ui.mine.SecondActivityAlias2" ) val iPackageManager: PackageManager = context.getPackageManager() //禁用活动/便捷入口 iPackageManager .setComponentEnabledSetting( aliasComponentName2, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP ) // 启用活动/便捷入口 iPackageManager.setComponentEnabledSetting(aliasComponentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }