【问题标题】:How to create dynamic URLs using Build Flavors in Android (Android Studio)如何在 Android (Android Studio) 中使用 Build Flavors 创建动态 URL
【发布时间】:2022-01-19 09:20:58
【问题描述】:

如何在 Android (Android Studio) 中使用 Build Flavors 创建动态 URL 我的应用程序中的每个环境都有超过 15 个 URL,我们总共有 5 个环境,我如何使用来自公共类的这些 URL,基于 Activated 构建变体。

【问题讨论】:

  • 我想您的问题与将处理打开活动链接的意图过滤器有关。对吗?

标签: android android-studio android-build-flavors android-variants


【解决方案1】:

在您的应用中创建一个用于切换环境的选项。

希望这些步骤对您有所帮助。

步骤->

  1. 创建一个用于处理所有 URL 的类。
  2. 根据环境显示点击更改 URL 的选项[在生产环境中隐藏此选项]
  3. 根据当前环境显示包含 URL 列表的 Dropbox
  4. 一旦用户选择一个 URL 重新启动应用程序。

【讨论】:

    【解决方案2】:

    在要处理动态链接的每个活动的清单中添加特定的意图过滤器。

            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
    
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <!-- Accepts URIs "https://myapp.com/<FLAVOR>/myoperation” -->
                <data
                    android:scheme="https"
                    android:host="myapp.com"
                    android:pathPrefix="@string/uri_myoperation_path_prefix" />
            </intent-filter>
    

    pathPrefix 来自特定于风味的资源字符串。

    <resources>
        <string name="uri_myoperation_path_prefix" translatable="false">/<FLAVOR>/myoperation</string>
    </resources>
    

    动态链接具有共同的方案和宿主,但每种风味都有一个特定的路径部分,因此该链接将仅由特定风味的应用程序打开。

    【讨论】:

      猜你喜欢
      • 2021-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-08
      • 2019-11-25
      • 2018-09-17
      • 1970-01-01
      • 2017-06-23
      相关资源
      最近更新 更多