From adab8e3ed865fa5a90633f5fe1465c34303a37ba Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 24 Jan 2022 09:26:08 -0500 Subject: [PATCH] Allow choosing browser apps from WebView even when extension deep links are verified in Android 12+ --- .../kanade/tachiyomi/util/system/ContextExtensions.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt index 85478c3c57..ca68c99978 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt @@ -292,12 +292,22 @@ fun Context.openInBrowser(uri: Uri, @ColorInt toolbarColor: Int? = null) { .build() ) .build() + // Force allowing browser selection for Android 12+ so that verified extensions don't + // re-open Tachiyomi + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + intent.intent.setPackage(defaultBrowserPackageName()) + } intent.launchUrl(this, uri) } catch (e: Exception) { toast(e.message) } } +fun Context.defaultBrowserPackageName(): String? { + val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("http://")) + return packageManager.resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY)?.activityInfo?.packageName +} + fun Context.createFileInCacheDir(name: String): File { val file = File(externalCacheDir, name) if (file.exists()) {