简体   繁体   English

如何在 Android (Android Studio) 中使用 Build Flavors 创建动态 URL

[英]How to create dynamic URLs using Build Flavors in Android (Android Studio)

How to create dynamic URLs using Build Flavors in Android (Android Studio) I have more than 15 URLs for each environment in my app, and in total we have 5 environments, how do I use these URLs from a common class, based on the Activated build variant.如何在 Android (Android Studio) 中使用 Build Flavors 创建动态 URL 我的应用程序中的每个环境都有超过 15 个 URL,总共有 5 个环境,我如何使用来自常见 class 的这些 URL,基于 Activated构建变体。

Create an option in you app for switching environments.在您的应用程序中创建一个用于切换环境的选项。

Hope these steps might help you.希望这些步骤可能对您有所帮助。

Steps ->步骤->

  1. Create a Class for handling all the URLs.创建一个 Class 来处理所有 URL。
  2. Show option for click change URLs based on the environment [Hide this option for production]根据环境显示单击更改 URL 的选项 [隐藏此选项以进行生产]
  3. Show a dropbox with the list of URLs based on the current environment根据当前环境显示包含 URL 列表的 Dropbox
  4. Once the user selects a URL restart the app.一旦用户选择 URL 重新启动应用程序。

Inside your manifest for each activity that will handle the dynamic link add a specific intent-filter.在将处理动态链接的每个活动的清单中添加特定的意图过滤器。

        <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>

where the pathPrefix comes from a flavor specific resource string.其中 pathPrefix 来自风味特定的资源字符串。

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

The dynamic link has common scheme and host but a specific path section for each flavor.动态链接具有共同的方案和主机,但每种风味都有一个特定的路径部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM