AppGallery Connect Remote Configuration allows you to manage parameters online. With the service, you can change the behavior and appearance of your app online without requiring users to update the app.
Remote Configuration provides cloud-based services, the console, and the client SDK. By integrating the client SDK, your app can periodically fetch parameter values delivered on the console to modify the app's behavior and appearance.
Build an app that can use AppGallery Connect Remote Configuration to configure the app UI text. Your app will be able to:
To integrate this service, you must complete the following preparations:

If you are using DevEco Studio, you can integrate the SDK by using the Maven repository into your DevEco Studio project before development.

// Configure the following address:
apply plugin: 'com.huawei.agconnect'
dependencies {
...
implementation "com.huawei.agconnect:agconnect-remoteconfig-harmony:1.2.0.300"
}

You can create a page in your DevEco Studio project and design the UI according to the following figure, with a text and a button for fetching parameters from Remote Configuration as required.
The sample code for the layout file is as follows:
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:greeting"
ohos:text="Greeting CodeLaber"
ohos:layout_alignment="horizontal_center"
ohos:height="match_content"
ohos:width="match_content"
ohos:top_margin="100"
ohos:left_margin="60"
ohos:right_margin="60"
ohos:multiple_lines="true"
ohos:text_color="#ff888888"
ohos:text_size="100"
/>
<Button
ohos:id="$+id:fetch_button"
ohos:text="Get Online config"
ohos:background_element="$graphic:background_ability_main"
ohos:height="match_content"
ohos:width="match_content"
ohos:top_margin="20"
ohos:left_margin="60"
ohos:right_margin="60"
ohos:multiple_lines="true"
ohos:text_size="100"
/>
</DirectionalLayout>
As you need to implement functions including localizing the greeting and changing the boldfaced status, the following parameters need to be designed:
When an app is launched, it loads default parameter values. In this codelab, you will use in-app default parameter values. Create an XML file (for example, remote_config.xml) in the resources/base directory and set the default value for each parameter.
<?xml version="1.0" encoding="utf-8"?>
<remoteconfig>
<value> key="GREETING_KEY">Greeting, CodeLaber</value>
<value> key="SET_BOLD_KEY">false</value>
</remoteconfig>




import com.huawei.agconnect.remoteconfig.AGConnectConfig;
import com.huawei.agconnect.remoteconfig.ConfigValues;
import com.huawei.agconnect.remoteconfig.ResourceTable;
import com.huawei.hmf.tasks.OnFailureListener;
import com.huawei.hmf.tasks.OnSuccessListener;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.text.Font;
private static final String GREETING_KEY = "GREETING_KEY";
private static final String SET_BOLD_KEY = "SET_BOLD_KEY";
private AGConnectConfig config;
private Text text;
super.setUIContent(ResourceTable.Layout_ability_main);
text = (Text) findComponentById(ResourceTable.Id_greeting);
Button button = (Button) findComponentById(ResourceTable.Id_fetch_button);
config = AGConnectConfig.getInstance();
config.applyDefault(ResourceTable.Profile_remote_config);
text.setText(config.getValueAsString(GREETING_KEY));
Boolean isBold = config.getValueAsBoolean(SET_BOLD_KEY);
if (isBold){
text.setFont(Font.DEFAULT_BOLD);
}
button.setClickedListener(new Component.ClickedListener() {
@Override
public void onClick(Component component) {
fetchAndApply();
}
});
The fetchAndApply method is defined as follows:
private void fetchAndApply(){
config.fetch(0).addOnSuccessListener(new OnSuccessListener<ConfigValues>() {
@Override
public void onSuccess(ConfigValues configValues) {
config.apply(configValues);
updateUI();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
text.setText("fetch setting failed: " + e.getMessage());
}
});
}
private void updateUI(){
String greeting = config.getValueAsString(GREETING_KEY);
Boolean isBold = config.getValueAsBoolean(SET_BOLD_KEY);
text.setText(greeting);
if (isBold){
text.setFont(Font.DEFAULT_BOLD);
}
}


Well done. You have successfully built your first app that integrates Remote Configuration and learned how to: