[Huawei Developers] Freemind R:
This is originally from HUAWEI Developer Froum

Forum link: https://forums.developer.huawei.com/forumPortal/en/home

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200528042618.93397259291007694723732810714822:50510611123041:2800:F875F48DD3A0B50F07794BC3ADABC07D72929297F2BB2E66FC0929B0DCE4367F.jpg"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200528042618.93397259291007694723732810714822:50510611123041:2800:F875F48DD3A0B50F07794BC3ADABC07D72929297F2BB2E66FC0929B0DCE4367F.jpg[/IMG]​

Introduction

Remote config is a feature that allows us to alter both the look and feel of our application without the need to publish any updates to the App Gallery. This works by allowing us to define in-app parameters that can be overridden from within the Huawei App Gallery Connect — these parameters can then be activated for either all or a defined selection of users.

This powerful feature gives us a range of new abilities when it comes to immediate updates, temporary changes or testing new features amongst users. Let’s take a dive and learn the what, why and how of Remote Config so we can learn how to use it to benefit both ourselves and our users

Use Cases

1. Releasing new functions by user percentage.

2. Display country/region-specific promotion content.

3. Personalized content recommendation based on Huawei Analytics.

4. Holiday theme adaptation.

Development Process

· Create sample application in android and configure into AGC.

· Enable Remote Configuration API.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200528032623.47798340154371902032949591428776:50510611123041:2800:39319554C87C98CD0B2E15131321C3AC11B61CD772F901B1D361499FBF001E33.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200528032623.47798340154371902032949591428776:50510611123041:2800:39319554C87C98CD0B2E15131321C3AC11B61CD772F901B1D361499FBF001E33.png[/IMG]​

· Download agconnect-service.json and add into app directory.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200528033401.94430311011033540303976173060901:50510611123041:2800:52E84B71B8C3C39D15F45E0A6E585BB5C52C7A9F5273260141D73D6D6AA1370F.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200528033401.94430311011033540303976173060901:50510611123041:2800:52E84B71B8C3C39D15F45E0A6E585BB5C52C7A9F5273260141D73D6D6AA1370F.png[/IMG]​

· Add remote config dependencies in the build.gradle file in app directory.

implementation 'com.huawei.agconnect:agconnect-remoteconfig:1.3.1.300'

· Open AGC select Demo project Growing->Remote Config Now enable Remote Config service

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200528033011.04233688992625761301934592510701:50510611123041:2800:7DB218A5396D4761781ADC9AEA6D53F0E6D5F177469420898664378B3E29B7EC.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200528033011.04233688992625761301934592510701:50510611123041:2800:7DB218A5396D4761781ADC9AEA6D53F0E6D5F177469420898664378B3E29B7EC.png[/IMG]​

After enabling service, you will get option

· Parameter Management.

· Condition Management.

Parameter Management:

Within Remote Config we define key-value pairs which are known as parameters. These parameters are then used to define the configuration values that are to be used within our app.

· Key — The key is a String used to define the identify for the parameter

· value — The value can be of any other data type and is used to represent the value of our defined parameter.

​

· After saving parameter management details we can check ,you can add, modify, delete in existing parameters.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200528034602.16175835898860106032919194281718:50510611123041:2800:C446B0C40916C1309F1D5FA946771D1724D7E89FB3629B67CBF70121222B6F17.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200528034602.16175835898860106032919194281718:50510611123041:2800:C446B0C40916C1309F1D5FA946771D1724D7E89FB3629B67CBF70121222B6F17.png[/IMG]​

Condition Management

Conditions are a collection of rules that we can use to target specific app instances —for example based on gender we can update new changes.

The conditional value itself is also represented as a key-value pair, it’s made up of:

· condition — The condition to be satisfied for the value to be used

§ App version

§ OS version

§ Language

§ Country/Region

§ Audience, etc..

· value — The value to be used if the condition is satisfied

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200528035012.20538166100689528470863581825239:50510611123041:2800:9FFC6CFB53C3441743AFD5C07EB7477682765608B1B0381A9493A5682911FA75.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200528035012.20538166100689528470863581825239:50510611123041:2800:9FFC6CFB53C3441743AFD5C07EB7477682765608B1B0381A9493A5682911FA75.png[/IMG]​

Let’s see code Implementation

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200528035207.04537245546142819664460575699154:50510611123041:2800:BB5579EC43498BD4757D5301C606E818FD152B4B4D2C1BA0F76F410E8303E455.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200528035207.04537245546142819664460575699154:50510611123041:2800:BB5579EC43498BD4757D5301C606E818FD152B4B4D2C1BA0F76F410E8303E455.gif[/IMG]​

· Create Instance for AGConnectConfig

AGConnectConfig config = AGConnectConfig.getInstance();

· Create config.xml file ,you can set default parameter values before connecting to remote config service.so that your app can run perfectly.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200528035142.12934947924657345765481400005734:50510611123041:2800:C619BC59F95E9836157AC8C222DFEA51D584510D6C2C65A00ED9E10CF42C4F0E.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200528035142.12934947924657345765481400005734:50510611123041:2800:C619BC59F95E9836157AC8C222DFEA51D584510D6C2C65A00ED9E10CF42C4F0E.png[/IMG]​

<?xml version="1.0" encoding="utf-8"?>
<remoteconfig>
<value key="version">1.0</value>
</remoteconfig>

· Call Api to pass default values this will effect immediately.

config.applyDefault(R.xml.remote_config);

· Fetching parameter values from Remote Configuration

config.fetch(fetchInterval).addOnSuccessListener(new OnSuccessListener<ConfigValues>() {
@Override
public void onSuccess(ConfigValues configValues) {
config.apply(configValues);
config.getMergedAll();
long remoteVersionCode = config.getValueAsLong("version");
if (currentVersionCode > remoteVersionCode) {
ShowUpdateAlert();
}
Toast.makeText(getBaseContext(), "RemoteVersionCode: "+String.valueOf(remoteVersionCode), Toast.LENGTH_LONG).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Toast.makeText(getBaseContext(), "Fetch Fail", Toast.LENGTH_LONG).show();
}
});

This is not the end. For full content, you can visit HUAWEI Developer Forum.​