DEV Community

Zachary Powell
Zachary Powell

Posted on

Integrating Huawei's Remote Configuration into an Android App

Remote Configuration allows you to change how your app works and looks on the cloud, without requiring any app upgrades. Here we'll take a look at a hands-on example of how to integrate Remote Configuration.

Enabling and Configuring Remote Configuration

Sign in to AppGallery Connect and click My projects.
Click your project card and select the app for which you want to enable Remote Configuration from the app drop-down list on the top.
Go to Grow > Remote Configuration. If this is your first time using Remote Configuration, click Use now in the upper right corner.
Image description
Then you'll be able to configure the service in AppGallery Connect.
On the Remote Configuration page, set parameter and their conditions.
First, click New parameter to add a parameter. You can set multiple conditional values for a parameter. That is, the parameter value will vary depending on the condition.
Image description
Click Save.
Click Release to make the configuration take effect. If you click Cancel, all changes will be discarded.
Click the Parameters tab, on which all parameters are listed.
Click in the upper right corner of the parameter card. You'll be able to view, modify, and delete parameters, and copy existing parameters as new ones.
On the Conditions tab, you can set different conditions for the parameter. For example, if you set Condition to Audience, the configured parameter value will be updated only for a specific user group.

Integrating SDKs

Add Maven repository configuration to the build.gradle file of your project

Open the app-level build.gradle file, and configure the Remote Configuration SDK, Analytics SDK, and AppGallery Connect Plugin

In AppGallery Connect, click My projects, and find your project from the list. Go to Project settings > General information, download the agconnect-services.json file, and save the file to the app directory of your Android project.

Image description

Developing Functions

In this step, the Remote Configuration SDK will be used to set in-app default values and fetch parameter values from the cloud.
Add a default value configuration XML file, for example, remote_config.xml, to the res/xml directory of your Android Studio project. In the file, key-value pairs are in testvalue format.

Call applyDefault to pass the default values.

You can also create a Map object, and call applyDefault to read and pass the default values.

You can apply parameter values fetched from the cloud either immediately or upon the next launch of your app.

Fetch parameter values and apply them immediately

The following code applies parameter values immediately.

In the code, call the fetch API to fetch parameter values from the cloud, and then call the apply API to apply the parameter values in the fetching callback immediately.

Fetch parameter values and apply them upon the next launch of your app.

The following code applies parameter values upon the next launch of your app.

In the code, call loadLastFetched to obtain the parameter values fetched by calling the fetch API, and call the apply API to apply the parameter values.

Obtain the value for a single parameter

You can call an API to obtain the value for a parameter of a specific type from parameter values fetched from the cloud. The APIs for different parameter types are listed below

Obtain all parameter values

You can obtain all in-app default parameter values and on-cloud parameter values by calling getMergedAll.

For details, please refer to the development guide for Remote Configuration.

Discussion (0)