Skip to content

Commit b98c16d

Browse files
committed
Add a fallback for "Test interception" failures
Unclear how, but there's definitely rare real world error reports for https://amiusing with pkg=com.android.chrome.
1 parent 36f4e4d commit b98c16d

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

app/src/main/java/tech/httptoolkit/android/MainActivity.kt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,10 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
413413

414414
private fun openDocs() {
415415
app.trackEvent("Button", "open-docs")
416-
val browserIntent = Intent(Intent.ACTION_VIEW,
416+
startActivity(Intent(
417+
Intent.ACTION_VIEW,
417418
Uri.parse("https://httptoolkit.tech/docs/guides/android")
418-
)
419-
startActivity(browserIntent)
419+
))
420420
}
421421

422422
private fun testInterception() {
@@ -446,7 +446,21 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
446446
).apply {
447447
if (testBrowser != null) setPackage(testBrowser)
448448
}
449-
startActivity(browserIntent)
449+
450+
try {
451+
startActivity(browserIntent)
452+
} catch (e: ActivityNotFoundException) {
453+
if (browserIntent.`package` != null) {
454+
// If we tried a specific package, and it failed, try again with the simplest
455+
// plain HTTP catch-all VIEW intent, and hope something somewhere can handle it.
456+
startActivity(Intent(
457+
Intent.ACTION_VIEW,
458+
Uri.parse("http://amiusing.httptoolkit.tech")
459+
))
460+
} else {
461+
throw e
462+
}
463+
}
450464
}
451465

452466
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

0 commit comments

Comments
 (0)