We have installed applications programmatically.
A simpler implementation using Kotlin
fun PackageManager.isAppInstalled(packageName: String): Boolean =
getInstalledApplications(PackageManager.GET_META_DATA)
.firstOrNull { it.packageName == packageName } != null
And call it like this (seeking for Spotify app):
packageManager.isAppInstalled("com.spotify.music")