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 ->
- Create a Class for handling all the URLs.
- Show option for click change URLs based on the environment [Hide this option for production]
- Show a dropbox with the list of URLs based on the current environment
- 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.