Skip to content

Commit

Permalink
feat: support opening links to allowed domains from other apps
Browse files Browse the repository at this point in the history
  • Loading branch information
ShlomoCode committed Jun 22, 2024
1 parent 2f689fd commit 7c4b8c2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
29 changes: 27 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@ plugins {
id 'com.android.application'
}

def allowedDomains = System.getenv('ALLOWED_DOMAINS') ?: 'example.com'

def generateIntentFilterData() {
def intentHosts = []
def startupUrl = System.getenv('STARTUP_URL')

if (startupUrl) {
intentHosts << new URI(startupUrl).getHost()
} else {
def domains = allowedDomains.split(',')
for (int i = 0; i < Math.min(domains.size(), 10); i++) {
intentHosts << domains[i]
}
}

def intentFilterData = ''
intentHosts.each { host ->
intentFilterData += """
<data android:host="${host}" android:scheme="https" />
"""
}
return intentFilterData
}

android {
signingConfigs {
Expand All @@ -16,15 +39,17 @@ android {
compileSdkVersion 34

defaultConfig {
buildConfigField "String", "ALLOWED_DOMAINS", "\"${System.getenv('ALLOWED_DOMAINS') ?: 'example.com'}\""
buildConfigField "String", "STARTUP_URL", "\"${System.getenv('STARTUP_URL') ?: '' }\""
buildConfigField "String", "ALLOWED_DOMAINS", "\"${allowedDomains}\""
buildConfigField "String", "STARTUP_URL", "\"${System.getenv('STARTUP_URL') ?: ''}\""
buildConfigField "String", "VIEW_MODE", "\"${System.getenv('VIEW_MODE') ?: 'AUTO'}\""
buildConfigField "boolean", "BLOCK_MEDIA", "${System.getenv('BLOCK_MEDIA') ?: 'false'}"
buildConfigField "boolean", "BLOCK_ADS", "${System.getenv('BLOCK_ADS') ?: 'true'}"
buildConfigField "boolean", "NO_SSL", "${System.getenv('NO_SSL') ?: 'false'}"
resValue "string", "app_name", System.getenv('APP_NAME') ?: "My Application"
applicationId System.getenv('APPLICATION_ID') ?: "com.webview.myapplication"

manifestPlaceholders = [intentFilterData: generateIntentFilterData()]

minSdkVersion 16
targetSdkVersion 34
versionCode 1
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
${intentFilterData}
</intent-filter>
</activity>

Expand Down

0 comments on commit 7c4b8c2

Please sign in to comment.