Skip to content

Commit d1b9949

Browse files
committed
feat: added android app intent links
1 parent 53d23cc commit d1b9949

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@
3232

3333
<category android:name="android.intent.category.LAUNCHER" />
3434
</intent-filter>
35+
36+
<intent-filter android:autoVerify="true">
37+
<action android:name="android.intent.action.VIEW" />
38+
39+
<category android:name="android.intent.category.DEFAULT" />
40+
<category android:name="android.intent.category.BROWSABLE" />
41+
42+
<data android:host="www.melvinjonesrepol.com" android:scheme="https" />
43+
</intent-filter>
3544
</activity>
3645
</application>
3746

app/src/main/assets/css/error.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
html {
1+
html, body {
22
height: 100%;
33
margin: 0;
44
}

app/src/main/java/com/mrepol742/webappp/MainActivity.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import com.mrepol742.webappp.utils.DynamicShortcut
1919

2020

2121
class MainActivity : ComponentActivity() {
22-
private val allowedDomain = "www.melvinjonesrepol.com"
22+
private val allowedDomain = "melvinjonesrepol.com"
2323
private var currentUrl: String = "https://$allowedDomain"
2424
private val shortcuts = listOf(
2525
"/projects" to "My Projects",
@@ -61,13 +61,12 @@ class MainActivity : ComponentActivity() {
6161
override fun onResume() {
6262
super.onResume()
6363

64-
val urlFromIntent = when (intent?.action) {
65-
Intent.ACTION_VIEW -> intent.getStringExtra("url")
66-
else -> null
67-
}
64+
val urlFromData = intent?.data?.toString()
65+
val urlFromExtra = intent?.getStringExtra("url")
66+
val url = urlFromData ?: urlFromExtra
6867

69-
if (!urlFromIntent.isNullOrEmpty()) {
70-
currentUrl = urlFromIntent
68+
if (!url.isNullOrEmpty()) {
69+
currentUrl = url
7170
webViewState.value?.loadUrl(currentUrl)
7271
}
7372
}

app/src/main/java/com/mrepol742/webappp/client/SecureWebViewClient.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ class SecureWebViewClient(
9797
}
9898
"http", "https" -> {
9999
val host = uri.host ?: return false
100-
val allowedDomainRegex = Regex("(^|\\.)${Regex.escape(allowedDomain)}$", RegexOption.IGNORE_CASE)
101-
if (allowedDomainRegex.matches(host)) {
100+
val allowedDomainRegex = Regex("^(.*\\.)?${Regex.escape(allowedDomain)}$")
101+
val isAllowed = allowedDomainRegex.matches(host)
102+
103+
if (isAllowed) {
102104
false // load in WebView
103105
} else {
104106
openInCustomTab(uri)

0 commit comments

Comments
 (0)