privatefungetAllLauncherApps(): MutableList<AppInfo> { val list = ArrayList<AppInfo>() val launchIntent = Intent(Intent.ACTION_MAIN, null) .addCategory(Intent.CATEGORY_HOME) val intents = packageManager.queryIntentActivities(launchIntent, 0)
//遍历 for (ri in intents) { //得到包名 val packageName = ri.activityInfo.applicationInfo.packageName if (packageName == "com.android.settings") { //不显示原生设置 continue } //得到图标 val icon = ri.loadIcon(packageManager) //得到应用名称 val appName = ri.loadLabel(packageManager).toString()
//封装应用信息对象 val appInfo = AppInfo(icon, appName, packageName) //添加到list list.add(appInfo) } return list }
publicbooleanconfigureContentView(List<Intent> payloadIntents, Intent[] initialIntents, List<ResolveInfo> rList, boolean alwaysUseOption){ // The last argument of createAdapter is whether to do special handling // of the last used choice to highlight it in the list. We need to always // turn this off when running under voice interaction, since it results in // a more complicated UI that the current voice interaction flow is not able // to handle. mAdapter = createAdapter(this, payloadIntents, initialIntents, rList, mLaunchedFromUid, alwaysUseOption && !isVoiceInteraction());