It seems Samsung utilizes a separate user profile mechanism for dual messenger apps. To access these apps, we can gather the app list from all user profiles, filtering out the ones we already have. This will leave us with the dual messenger apps that we can then launch using the LauncherApps service.
Here's how we get the list of all apps (includes dual messenger apps)
suspend fun getAppsList(context: Context): MutableList<App> {
return withContext(Dispatchers.IO) {
val appList: MutableList<App> = mutableListOf()
try {
val userManager = context.getSystemService(Context.USER_SERVICE) as UserManager
val launcherApps = context.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
val collator = Collator.getInstance()
for (profile in userManager.userProfiles) {
for (app in launcherApps.getActivityList(null, profile)) {
val appLabelShown = app.label.toString()
val appModel = App(app.applicationInfo.packageName, appLabelShown, profile)
val appAlreadyExists =
appList.any { existingApp ->
existingApp.packageName == appModel.packageName && existingApp.user == appModel.user
}
if (app.applicationInfo.packageName != BuildConfig.APPLICATION_ID && !appAlreadyExists) {
appList.add(appModel)
}
}
}
appList.sortBy { it.appName.lowercase() }
} catch (e: Exception) {
e.printStackTrace()
}
appList
}
}
And here's how we launch an app
private fun launchApp(packageName: String, userHandle: UserHandle) {
val launcher = appContext.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
val activityInfo = launcher.getActivityList(packageName, userHandle)
val component =
when (activityInfo.size) {
0 -> {
// Handle app not found case
return
}
1 -> ComponentName(packageName, activityInfo[0].name)
else -> ComponentName(packageName, activityInfo.last().name)
}
try {
launcher.startMainActivity(component, userHandle, null, null)
} catch (e: SecurityException) {
try {
launcher.startMainActivity(component, android.os.Process.myUserHandle(), null, null)
} catch (e: Exception) {
// Handle unable to open app case
}
} catch (e: Exception) {
// Handle unable to open app case
}
}
I found this method in Olauncher(Github), does exactly what I want lists and launch all apps including Dual messenger apps