Skip to content

Commit 9fd6715

Browse files
Titouan Thibaudtitooan
authored andcommitted
Fix Deeplink handling when the app is already opened
1 parent 591c461 commit 9fd6715

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

app/src/androidTest/java/org/mozilla/tryfox/MainActivityDeeplinkTest.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,25 @@ class MainActivityDeeplinkTest {
5050
composeTestRule.onNodeWithText(revision).assertExists()
5151
}
5252
}
53+
54+
@Test
55+
fun testDeeplink_whenAppIsAlreadyOpen_populatesRevision() {
56+
// Launch the app first
57+
ActivityScenario.launch(MainActivity::class.java)
58+
59+
val project = "autoland"
60+
val revision = "abcdef123456"
61+
val deeplinkUri = Uri.parse("https://treeherder.mozilla.org/#/jobs?repo=$project&revision=$revision")
62+
val intent = Intent(ApplicationProvider.getApplicationContext(), MainActivity::class.java).apply {
63+
action = Intent.ACTION_VIEW
64+
data = deeplinkUri
65+
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
66+
}
67+
68+
// Now send the deeplink intent
69+
ApplicationProvider.getApplicationContext<android.content.Context>().startActivity(intent)
70+
71+
composeTestRule.waitForIdle()
72+
composeTestRule.onNodeWithText(revision).assertExists()
73+
}
5374
}

app/src/main/java/org/mozilla/tryfox/MainActivity.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ class MainActivity : ComponentActivity() {
5656
}
5757
}
5858

59+
override fun onNewIntent(intent: Intent) {
60+
super.onNewIntent(intent)
61+
Log.d("MainActivity", "onNewIntent called. Intent: $intent, Data: ${intent.data}")
62+
setIntent(intent)
63+
if (::navController.isInitialized) {
64+
navController.handleDeepLink(intent)
65+
}
66+
}
67+
5968
private fun installApk(file: File) {
6069
val fileUri: Uri = FileProvider.getUriForFile(
6170
this,

0 commit comments

Comments
 (0)