Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion app/src/main/java/dev/trooped/tvquickbars/utils/AppUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,36 @@ fun Context.getBestLaunchIntent(packageName: String): Intent? {
}
}

// 4. Special case: Amazon Prime Video
// 4. Aggressive fallback: scan all declared activities for a likely entry point
try {
val packageInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
pm.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(PackageManager.GET_ACTIVITIES.toLong()))
} else {
@Suppress("DEPRECATION")
pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
}

val activities = packageInfo.activities
if (activities != null && activities.isNotEmpty()) {
val entryPointKeywords = listOf("main", "splash", "tv", "leanback", "launcher", "home")

val exported = activities.filter { it.exported }
val candidates = exported.ifEmpty { activities.toList() }

val bestMatch = candidates.firstOrNull { activity ->
val name = activity.name.lowercase()
entryPointKeywords.any { keyword -> name.contains(keyword) }
} ?: candidates[0]

return Intent(Intent.ACTION_MAIN).apply {
component = ComponentName(packageName, bestMatch.name)
}
}
} catch (_: PackageManager.NameNotFoundException) {
// Package not installed, fall through
}

// 5. Special case: Amazon Prime Video
if (packageName == "com.amazon.amazonvideo.livingroom") {
val knownActivities = listOf(
"com.amazon.ignition.IgnitionActivity",
Expand Down