Home > Blockchain >  How to create dynamic URLs using Build Flavors in Android (Android Studio)
How to create dynamic URLs using Build Flavors in Android (Android Studio)

Time:12-17

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.

CodePudding user response:

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.
  2. Show option for click change URLs based on the environment [Hide this option for production]
  3. Show a dropbox with the list of URLs based on the current environment
  4. Once the user selects a URL restart the app.

CodePudding user response:

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.

<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, so the link will be opened only by the specific flavored app.

  • Related