AndroidManifest设置
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<!-- 设置两项 -->
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
获取启动项
// 获取启动图标集合
val intent = Intent(Intent.ACTION_MAIN, null)
intent.addCategory(Intent.CATEGORY_LAUNCHER)
val resolveInfos = resolveInfos.addAll(packageManager.queryIntentActivities(intent, 0))
启动
// 获取信息
val resolveInfo = resolveInfos.getOrNull(position)
resolveInfo?.let {
// 包名
val pkg = it.activityInfo.packageName
// 类名
val cls = it.activityInfo.name
// 启动
startActivity(Intent().apply { component = ComponentName(pkg, cls) })
}