Skip to content

Commit

Permalink
Add a fallback for "Test interception" failures
Browse files Browse the repository at this point in the history
Unclear how, but there's definitely rare real world error reports for
https://amiusing with pkg=com.android.chrome.
  • Loading branch information
pimterry committed Sep 9, 2020
1 parent 36f4e4d commit b98c16d
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions app/src/main/java/tech/httptoolkit/android/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,10 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {

private fun openDocs() {
app.trackEvent("Button", "open-docs")
val browserIntent = Intent(Intent.ACTION_VIEW,
startActivity(Intent(
Intent.ACTION_VIEW,
Uri.parse("https://httptoolkit.tech/docs/guides/android")
)
startActivity(browserIntent)
))
}

private fun testInterception() {
Expand Down Expand Up @@ -446,7 +446,21 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
).apply {
if (testBrowser != null) setPackage(testBrowser)
}
startActivity(browserIntent)

try {
startActivity(browserIntent)
} catch (e: ActivityNotFoundException) {
if (browserIntent.`package` != null) {
// If we tried a specific package, and it failed, try again with the simplest
// plain HTTP catch-all VIEW intent, and hope something somewhere can handle it.
startActivity(Intent(
Intent.ACTION_VIEW,
Uri.parse("http://amiusing.httptoolkit.tech")
))
} else {
throw e
}
}
}

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

0 comments on commit b98c16d

Please sign in to comment.