skip to Main Content

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.

2

Answers


  1. 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.
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search