Remote Configuration on Android
Remote Configuration allows you to change the appearance and behavior of your application without updating.
When using Remote Configuration, we create in-app default parameters and values that control the appearance and behavior of our app. We can then manage these parameters and their new values on Console to update the values.
You can create the necessary parameters and values on the Console and reflect the changes to your application without publishing any updates in line with these parameters.
Images, texts, colors etc. in the app. You can change the variables easily with this service. For example, special theme / icon changes on special days, messages specific to the day and region, content changes depending on the language and the region, etc.
However, it is beneficial not to add confidential data based on user authorization to these parameters.
HUAWEI AppGallery Connect provides the Remote Configuration service for you to manage parameters online. With this service, the online behavior and appearance of the application can be changed without users having to update the application.
Provides Remote Configuration, cloud-based services, console and client SDK. By integrating the client SDK, your application can periodically retrieve the parameter values presented in the console to change the application’s behavior and appearance.
Functions
1. Service provision.
2. Parameter management: It includes adding, deleting and changing parameters, copying and changing existing parameters as new ones, and setting conditional values.
3. State management: Includes adding, deleting and changing conditions and copying and modifying existing conditions as new. The conditions you can set right now are: version, language, country / region, target audience, user attribute, percentage of users, and time. More conditions will be available in the future.
4. Version management: Supports management and rollback of up to 300 versions for parameters and conditions.
5. Permission management: Allows the account holder, administrator, application manager, R&D personnel, and operations personnel to access Remote Configuration by default.
Basic Procedure
1. Log in to AppGalery Connect, enable Remote Configuration for your application, and set parameters and conditions.
2. Integrate AppGallery Connect Remote Configuration SDK into your application.
3. Set default parameter values in your application so that it can work properly before connecting to Remote Configuration.
4. Call the fetch method provided by the SDK to periodically receive parameter value updates from Remote Configuration. When receiving a request from the application, Remote Configuration checks if a declared parameter has a value in the cloud and returns the value if it does.
5. After receiving the parameter value updates, the application calls the apply () method immediately or at a specified time according to service requirements to override the values in the application with the obtained values.
6. Call the various retrieval methods provided by the SDK to dynamically obtain parameter values from Remote Configuration.
Use Cases
• Displaying Different Languages by Country / Region
You can schedule a promotion by setting a trigger in Remote Configuration. More importantly, promotional content may vary by country or region, as long as you set local information in Remote Configuration. For example, it may display different languages for users in China and Australia.
• Displaying Different Content to Different Users
Remote Configuration can work with HUAWEI Analytics to customize content displayed to different user groups. For example, different products and UI layouts can be shown in an application for office workers and students
• Adapting the Application Theme According to Time
You can set the clock condition, different app colors and various picture materials in Remote Configuration to change the app theme to a custom time. For example, during the graduation season, you can adapt your app to the graduation theme to attract more users.
• Release of New Functions
Publishing new functions to all users at the same time can be risky. Remote Configuration allows new functionality version based on user percentage to slowly increase target user coverage and effectively helps you improve your app based on feedback from users already exposed to new functionality
You can find the details of the necessary pre-development steps at RemoteConfig SDK Preparation and Project Integration.
The main methods are:
containKey(String key) : Checks whether the ConfigValues object contains a requested key.
getValueAsBoolean(String key) : Returns the boolean type value for key.
getValueAsDouble(String key) : Returns the double type value for key.
getValueAsLong(String key) : Returns the long type value for key.
getValueAsString(String key) : Returns the string type value for key.
getValueAsByteArray(String key) : Returns the byteArray type value for key
Setting Default In-Application Parameter Values
Get an instance of the Remote Configuration object.
1
AGConnectConfig config = AGConnectConfig.getInstance();
You can set in-app default parameter values in the Remote Configuration object so that your app can run properly before connecting to Remote Configuration, and if the parameter values are not set in the console, the in-app default values are used. Currently, you can define in-app default parameter values in one of the following ways:
Using an XML source file
Add a default value XML file (for example, remote_config.xml) to the res / xml folder of your Android Studio project. In the file, the key / value pairs are of the format <value key = “testkey”> testvalue </value>.
<remoteconfig>
<value
key="test1">test1</value>
<value
key="test2">true</value>
<value
key="test3">123</value>
<value
key="test4">123.456</value>
<value
key="test5">test-test</value>
</remoteconfig>
You can call the API below to pass default values that will take effect immediately.
config.applyDefault(R.xml.remote_config)
Using a map object
The Map object supports only string, boolean, and numeric values. Other types of values will be ignored. Example An example configuration code:
Map<String, Object> map = new
HashMap<>();
map.put("test1", "test1");
map.put("test2", "true");
map.put("test3", 123);
map.put("test4", 123.456);
map.put("test5", "test-test");
config.applyDefault(map);
Setting Parameter Values in Remote Configuration
You can create parameter values to override in-app parameter values based on conditions defined in AppGallery Connect or target users.
Define the parameters using the same names used in your application. You can set the default value (which will override the corresponding in-app default value) and conditional values for each parameter.
Parameter Management
1. Log in to AppGallery Connect and select My Projects.
2. Find your project in the project list and click on the application you need to set the parameters in the project card. Go to Growing> Remote Configuration.
3. You can add, delete and change parameters on this tab page by clicking the Parameter Management tab. You can copy and replace existing parameters as new ones and set conditional parameter values.
4. You can add a parameter by clicking Add Parameter.
You can set multiple conditional values for a parameter. That is, the parameter value will change depending on the situation.
To add a parameter similar to the existing one, click Duplicate next to the existing parameter and make some changes.
Condition / Situation Management
1. Log in to AppGallery Connect and select My Projects.
2. Find your project in the project list and click on the application you need to set the parameters in the project card. Go to Growing> Remote Configuration.
3. You can add, delete and change conditions on this tab page by clicking the Condition Management tab. You can copy and change the current conditions as new conditions.
4. You can add a condition by clicking Add Condition.
For example :
Filter Condition: App Version
Operator: Include / Exclude / Equal / Include regular expression
Value: One or more application version numbers
Explanation :
For an Android app, the version number is obtained from the VersionName value.
If the selected operator is Include, Exclude, or Equal, you can use a comma (,) separated list of values.
If the selected operator is Include regular expression, you can use RE2 format to create a regular expression. Using a regular expression, you can match not only the entire text of the target version string, but also the beginning, end, or full text of the target string using the ^ and $ links.
The Equal operator specifies that if any value in the target value list is true, then True is returned. For example, if the target value is 1.0, 2.0, 3.0, then True is returned when the actual value is 2.0, and False is returned when the actual value is 4.0.
The Include operator specifies that True if any value in the target value list is a substring of the real value. For example, if the target value is 1.0, 2.0, 3.0, then True is returned when the actual value is 2.0.1, and False is returned when the actual value is 4.0.1.
The Exclude operator specifies that True is returned if no value in the target value list is a substring of the actual value. For example, if the target value is 1.0, 2.0, 3.0, False is returned when the actual value is 2.0.1, and True is returned when the actual value is 4.0.1.
The Include regular expression operator specifies that the target value (regular expression in RE2 format) is returned True when it matches the actual value.
For other Condition Managements, you can examine the Condition Management subtitle at Integrating Remote Configuration
The meanings of its operators are as follows:
Each ellipse shows the audience, and multiple ellipses indicate that multiple audiences are selected for the target value. The rectangle shows all users of an application. Gray sections indicate users meeting operators.
To add a condition similar to existing conditions, you can click Duplicate next to the current condition and make some changes.
If there are multiple conditions, you can click and drag the condition cards to adjust the condition order.
Version Management
Version Management Supports management and rollback of up to 300 versions for Remote Configuration, parameters and conditions.
Retrieving Parameter Values from Remote Configuration
You can call fetch() API to get parameter values from Remote Configuration in asynchronous mode. After the API has been successfully called, data of the ConfigValues type will be returned from Remote Configuration.
If you use the ConfigValues class, you can only get parameter values in the cloud. After receiving the parameter value updates, the apply() method should be called immediately or at a specified time according to service requirements to update / invalidate the values in the application with the obtained values.
config.fetch().addOnSuccessListener(new
OnSuccessListener<ConfigValues>() {
@Override
public
void
onSuccess(ConfigValues configValues) {
config.apply(configValues);
}
}).addOnFailureListener(new
OnFailureListener() {
@Override
public
void
onFailure(Exception e) {
}
});
The default interval for calling the fetch()method is 12 hours. You can call the fetch (long intervalSeconds) method to customize the fetch interval. Calling the fetch() method within a specified range will retrieve locally cached data instead of retrieving data from the cloud.
The fetch interval specified by the fetch (long intervalSeconds) method is in seconds. It is recommended to set this range to a small value during debugging to facilitate commissioning, and to a large value during production to avoid the effect of flow control.
Obtaining Parameter Values According to Data Type
Once the default parameter values are set or the parameter values are fetched from the Remote Configuration, you can call any of the APIs provided by the SDK, by data type, to obtain the parameter values to be used in your application:
• getValueAsBoolean(String key)
• getValueAsDouble(String key)
• getValueAsLong(String key)
• getValueAsString(String key)
• getValueAsByteArray(String key)
Parameter values set in Remote Configuration are stored as character strings. Once obtained, the values are converted to the desired data type. If the conversion fails, the default value of the requested data type is returned
• DEFAULT.BOOLEAN_VALUE = false
• DEFAULT.DOUBLE_VALUE = 0.0
• DEFAULT.LONG_VALUE = 0L
• DEFAULT.STRING_VALUE = “”
• DEFAULT.BYTE_ARRAY_VALUE = new byte[0]
You can call the getSource() API to obtain the source of a value. Data sources are as follows:
• SOURCE.STATIC: default value of the data type.
• SOURCE.DEFAULT: in-app default value.
• SOURCE.REMOTE: value obtained from Remote Configuration.
Note:
The boolean value true is returned for the following character strings: 1, true, t, yes, y, on.
The boolean value false is returned for the following character strings: 0, false, f, no, n, off.
Obtaining All Parameter Values
You can get all in-app default values and parameter values on the cloud in one go. For the same parameter key, the value on the cloud is used with priority.
Map<String,Object> map = config.getMergedAll();
Reset Parameter Values
You can clear all parameter values, including in-app parameter values and parameter values on the cloud, by calling the clearAll() method.
config.clearAll();
Relevant links for more details:
Integrating Remote Configuration
Remote Configuration