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.
How to create dynamic URLs using Build Flavors in Android (Android Studio)
651 Views Asked by Shubham Vyas At
2
There are 2 best solutions below
0
On
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.
Create an option in you app for switching environments.
Hope these steps might help you.
Steps ->