From 7c4b8c22503226dec9389e75681b7dfd5c81fb69 Mon Sep 17 00:00:00 2001 From: ShlomoCode <78599753+ShlomoCode@users.noreply.github.com> Date: Sun, 23 Jun 2024 01:30:57 +0300 Subject: [PATCH] feat: support opening links to allowed domains from other apps --- app/build.gradle | 29 +++++++++++++++++++++++++++-- app/src/main/AndroidManifest.xml | 4 ++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index eaf500a..161e877 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 += """ + + """ + } + return intentFilterData +} android { signingConfigs { @@ -16,8 +39,8 @@ 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'}" @@ -25,6 +48,8 @@ android { 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 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6ddd991..f7b3f7a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -33,6 +33,10 @@ + + + + ${intentFilterData}