Skip to content

Commit 0fb89bd

Browse files
committed
Let MainActivity manage Element Call https links.
1 parent b055452 commit 0fb89bd

File tree

4 files changed

+42
-12
lines changed

4 files changed

+42
-12
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@
7676
</intent-filter>
7777
<!--
7878
Element web links
79-
Note: On Android 12 and higher clicking a web link (that is not an Android App Link) always shows content in a web browser
80-
https://developer.android.com/training/app-links#web-links
8179
-->
8280
<intent-filter android:autoVerify="true">
8381
<action android:name="android.intent.action.VIEW" />
@@ -86,8 +84,7 @@
8684
<category android:name="android.intent.category.BROWSABLE" />
8785

8886
<data android:scheme="https" />
89-
<data android:host="app.element.io" />
90-
<data android:host="develop.element.io" />
87+
<data android:host="*.element.io" />
9188
</intent-filter>
9289
<!--
9390
matrix.to links

app/src/main/kotlin/io/element/android/x/MainActivity.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import io.element.android.compound.theme.ElementTheme
3939
import io.element.android.compound.theme.Theme
4040
import io.element.android.compound.theme.isDark
4141
import io.element.android.compound.theme.mapToTheme
42+
import io.element.android.features.call.ui.ElementCallActivity
4243
import io.element.android.features.lockscreen.api.handleSecureFlag
4344
import io.element.android.features.lockscreen.api.isLocked
4445
import io.element.android.libraries.architecture.bindings
@@ -58,6 +59,13 @@ class MainActivity : NodeActivity() {
5859
Timber.tag(loggerTag.value).w("onCreate, with savedInstanceState: ${savedInstanceState != null}")
5960
installSplashScreen()
6061
super.onCreate(savedInstanceState)
62+
if (ElementCallActivity.maybeStart(this, intent)) {
63+
Timber.tag(loggerTag.value).w("Starting Element Call Activity")
64+
if (savedInstanceState == null) {
65+
finish()
66+
return
67+
}
68+
}
6169
appBindings = bindings()
6270
appBindings.lockScreenService().handleSecureFlag(this)
6371
enableEdgeToEdge()
@@ -135,11 +143,18 @@ class MainActivity : NodeActivity() {
135143
* Called when:
136144
* - the launcher icon is clicked (if the app is already running);
137145
* - a notification is clicked.
146+
* - a deep link have been clicked
138147
* - the app is going to background (<- this is strange)
139148
*/
140149
override fun onNewIntent(intent: Intent) {
141150
super.onNewIntent(intent)
142151
Timber.tag(loggerTag.value).w("onNewIntent")
152+
153+
if (ElementCallActivity.maybeStart(this, intent)) {
154+
Timber.tag(loggerTag.value).w("Starting Element Call Activity")
155+
return
156+
}
157+
143158
// If the mainNode is not init yet, keep the intent for later.
144159
// It can happen when the activity is killed by the system. The methods are called in this order :
145160
// onCreate(savedInstanceState=true) -> onNewIntent -> onResume -> onMainNodeInit

features/call/src/main/AndroidManifest.xml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,10 @@
3434
android:configChanges="screenSize|screenLayout|orientation|keyboardHidden|keyboard|navigation|uiMode"
3535
android:launchMode="singleTask">
3636

37-
<intent-filter android:autoVerify="true">
38-
<action android:name="android.intent.action.VIEW" />
39-
<category android:name="android.intent.category.DEFAULT" />
40-
<category android:name="android.intent.category.BROWSABLE" />
37+
<!--
38+
Note: intent-filter for https://call.element.io link is now managed by the MainActivity.
39+
-->
4140

42-
<data android:scheme="https" />
43-
44-
<data android:host="call.element.io" />
45-
</intent-filter>
4641
<!-- Custom scheme to handle urls from other domains in the format: element://call?url=https%3A%2F%2Felement.io -->
4742
<intent-filter>
4843
<action android:name="android.intent.action.VIEW" />

features/call/src/main/kotlin/io/element/android/features/call/ui/ElementCallActivity.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.element.android.features.call.ui
1818

1919
import android.Manifest
20+
import android.app.Activity
2021
import android.content.Context
2122
import android.content.Intent
2223
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
@@ -35,6 +36,7 @@ import androidx.compose.runtime.collectAsState
3536
import androidx.compose.runtime.getValue
3637
import androidx.compose.runtime.mutableStateOf
3738
import androidx.compose.runtime.remember
39+
import androidx.core.app.ActivityOptionsCompat
3840
import androidx.core.content.IntentCompat
3941
import com.bumble.appyx.core.integrationpoint.NodeComponentActivity
4042
import io.element.android.compound.theme.ElementTheme
@@ -47,6 +49,7 @@ import io.element.android.features.call.di.CallBindings
4749
import io.element.android.features.call.utils.CallIntentDataParser
4850
import io.element.android.features.preferences.api.store.AppPreferencesStore
4951
import io.element.android.libraries.architecture.bindings
52+
import io.element.android.libraries.core.bool.orFalse
5053
import javax.inject.Inject
5154

5255
class ElementCallActivity : NodeComponentActivity(), CallScreenNavigator {
@@ -63,6 +66,26 @@ class ElementCallActivity : NodeComponentActivity(), CallScreenNavigator {
6366
}
6467
context.startActivity(intent)
6568
}
69+
70+
/**
71+
* Eventually start the ElementCallActivity, and return true if it's the case.
72+
*/
73+
fun maybeStart(
74+
activity: Activity,
75+
intent: Intent?,
76+
): Boolean {
77+
return intent?.data
78+
?.takeIf { uri -> uri.scheme == "https" && uri.host == "call.element.io" }
79+
?.let { uri ->
80+
val callIntent = Intent(activity, ElementCallActivity::class.java).apply {
81+
data = uri
82+
}
83+
// Disable animation since MainActivity has already been animated.
84+
val options = ActivityOptionsCompat.makeCustomAnimation(activity, 0, 0)
85+
activity.startActivity(callIntent, options.toBundle())
86+
true
87+
}.orFalse()
88+
}
6689
}
6790

6891
@Inject lateinit var callIntentDataParser: CallIntentDataParser

0 commit comments

Comments
 (0)