Remote Config : Dynamically Change your app’s Behavior - Huawei Developers

This is originally from HUAWEI Developer Froum
Forum link: https://forums.developer.huawei.com/forumPortal/en/home
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
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.
· Download agconnect-service.json and add into app directory.
· Add remote config dependencies in the build.gradle file in app directory.
Code:
implementation 'com.huawei.agconnect:agconnect-remoteconfig:1.3.1.300'
· Open AGC select Demo project Growing->Remote Config Now enable Remote Config service
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.
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
Let’s see code Implementation
· Create Instance for AGConnectConfig
Code:
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.
Code:
<?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.
Code:
config.applyDefault(R.xml.remote_config);
· Fetching parameter values from Remote Configuration
Code:
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.​

Related

Huawei Wallet Kit -Server Side Tickets and All-in-one pass Creation

This is originally from HUAWEI Developer Forum
Forum link: https://forums.developer.huawei.com/forumPortal/en/home​
Introduction
HUAWEI Wallet Kit providing users to claim passes of merchants, like loyalty cards, gift cards, coupons, boarding passes, event tickets, and transit passes. It provides easy-to-access digital passes on an integrated platform. It enables user save their cards into mobile phones for convenient. The interaction between apps and users via location based notifications.
Integration Process.
The Wallet Kit integration process consists following steps
1. Generating Public and Private Keys
2. Adding Pass type on the AGC
3. Running the Server Demo code
4. Running the Client Demo code
5. View card adding status
Step-1: Check Below Link to generate keys & App Configuration in AGC:
LINK: https://forums.developer.huawei.com...d=0201242460338530108&fid=0101187876626530001
· Let’s see how to apply new wallet.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
· Now will see how to create Flight ticket.
· Service type consists 3 types
1. Card
2. Coupon
3. Ticket
· Service item will change based on service type
· Service name should be Unique
· Service Id should be unique it will start will always hwpass
· Public key we need to get it from RSAUtils
· Click next button and save details. The service application procedure is now complete. After applying for the service, you can view, edit, and delete it on the HUAWEI Wallet Kit service application page
Step-2: Server Side Integration:
Download server demo code check below link.
Link: https://developer.huawei.com/consumer/en/doc/development/HMS-Examples/wallet-sample-code
1. Download maven dependency.
2. Configure your project into IntelliJ IDEA
3. Download required dependencies and import
4. Sync your project
5. Open release.config.properties and replace appId & secret Key
6. Compile project using terminal mvn clean compile
7. After completion of compilation automatically Target folder will generate
Follow below steps
Copy hmspass folder in the config directory, paste into the target/classes directory.
You can run the source code, you can run mainly java files in the Test folder.
Check below steps and modify accordingly.
· The file ends with ModelTest provides the examples of adding, modifying and pass models.
· The file name ends with InstanceTest provides the examples of adding, modifying and pass instances.
Step-3: Generate Pass Model:
· Open FlightModel.json file
· PassTypeIdentifier is unique which you mentioned service Id in AGC both needs to match
· You have to modify passTypeIdentifier and passStyleIdentifier when we add card types on the AGC PassStyleIdentifier field is unique.
· After completion of modify execute createFlightModel()
· Open the HwFlightModelTest file and Run CreateFlightModel() method
Code:
Test
public void createFlightModel() {
System.out.println("createFlightModel begin");
// Read an example flight model from a JSON file.
String objectJson = CommonUtil.readWalletObject("FlightModel.json");
HwWalletObject hwWalletObject = JSONObject.parseObject(objectJson, HwWalletObject.class);
String modelId = hwWalletObject.getPassStyleIdentifier();
System.out.println("modelId is: " + modelId);
String instanceId = hwWalletObject.getSerialNumber();
// Set parameters of the flight model you want to create. Flight instances belong to this model share these
// parameters.
WalletBuildService walletBuildService = new WalletBuildServiceImpl();
HwWalletObject requestData = walletBuildService.createHwWalletObject(objectJson, instanceId, modelId);
// Validate the parameters.
boolean validateModel = HwWalletObjectUtil.validateWalletModel(requestData);
if (validateModel) {
// Post the new flight model to the wallet server.
String urlParameter = "flight/model";
HwWalletObject flightModel = walletBuildService.postHwWalletObjectToWalletServer(urlParameter, requestData);
System.out.println("createFlightModel JSON is: " + CommonUtil.toJson(flightModel));
System.out.println("createFlightModel end");
}
}
This is not all. For full content, you can visit https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201254289105300220&fid=0101187876626530001
This is a great solution for wallet and loyalty apps that want to stay away from GMS.

Remote Configuration — A/B Testing | Use And Analyze New Features Without Any Update

More information like this, you can visit HUAWEI Developer Forum​
Original link: https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201332997357290022&fid=0101187876626530001
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Hello everyone. In this article, I would like to talk about Remote Configuration — A/B Testing. What are they and where are they used? I want to start with these.
Remote Configuration
With the service, you can make changes in the behavior and appearance of your application without any updates. This process is managed by determining various parameters on the Console.
Use Cases:
Displaying the Language by Country/Region
Displaying Different Content to Different Users
Adapting the App Theme by Time
Releasing New Functions
Configurations
Go to Growing> Remote Configuration. Click Enable now to enable Remote Configuration.
Add the Remote Configuration dependencies in the build.gradle file in the app directory.
Code:
implementation 'com.huawei.agconnect:agconnect-remoteconfig:1.4.0.300'
Development
I have prepared a demo app to explain this service better. I’ll talk about it step by step.
First, I set the parameter using the Parameter Management tab in the Remote Config tab.
Then I determined the condition in the Condition Management tab and defined it in the parameter tab.
After the integration process on AGC is completed, you can start writing code on the application. In the code part, you must first specify the parameter you defined in AGC. You can do this by using the “Map” object or “XML”. I used XML.
Code:
override fun onCreate(savedInstanceState: Bundle?)
{
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
/*
- Using a Map object
val mapDefault = mapOf("language" to "other",
"key2" to "val2",
"key3" to "val3",
"key4" to "val4")
- Using an XML resource file
<?xml version="1.0" encoding="utf-8"?>
<remoteconfig>
<value key="language">other</value>
</remoteconfig>
*/
val agConnectConfig = AGConnectConfig.getInstance()
agConnectConfig.applyDefault(R.xml.remote_config)
remoteButton = findViewById(R.id.remote)
remoteButton?.setOnClickListener {
agConnectConfig.fetch(0).addOnSuccessListener {
agConnectConfig.apply(it)
val languageResponse = agConnectConfig.getValueAsString("language")
Toast.makeText(this, languageResponse, Toast.LENGTH_LONG).show()
if (languageResponse == "en"){
showUpdateAlert("Language is English")
}
else if(languageResponse == "other"){
showUpdateAlert("Language is not English")
}
}.addOnFailureListener {
// fail fetching from remote config
it.printStackTrace()
}
}
}
After writing the code, you can test the Remote Configuration by making changes on the device according to the parameter.
A/B Testing
You can use the service to create one or more A/B tests engaging different user groups to compare your variants of app UI design, copywriting, product functions, or marketing activities for performance metrics and find the best one that meets user requirements.
Use Cases:
App UI Design Testing
App Copywriting Testing
App Function Testing
Configurations
Go to Growing > A/B Testing. Click Enable now in the upper right corner.
After the service is enabled, the page shown in the following figure is displayed.
Notifications Experiment:
When you want to send notifications to existing users, you can use the A/B Testing to find out which user is affected by what type of notification.
Remote Configuration Experiment:
You can use A/B Testing to determine specific behaviors for specific user groups in your application or if you want to learn how it affects users before updating your application.
Development
I used the Remote Configuration Experiment. I’ll try to explain the steps here.
Firstly, you need to access Analytics Kit to obtain the target experiment users and experiment data, and generate experiment reports.
Enable Analytics Kit
Add the following code to the build.gradle file in the app directory
Code:
implementation 'com.huawei.hms:hianalytics:4.0.2.300'
Create User Attributes in this way to use the User Attributes condition.
Create a condition on the Remote Configuration tab.
Use Conditions to create your parameter.
Then you will see a four-step screen when you press the Create Remote Configuration Experiment button on the A/B Testing tab.
Set the basic information of the test.
Specify the conditions for finding the target users in this step.
In this step, select your Remote Configuration parameter.
You can select the indicators you want to see as a result of the test. A maximum of 5 options can be selected.
After these steps, you can start writing your code based on the conditions in your application.
Code:
override fun onCreate(savedInstanceState: Bundle?)
{
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
/*
- Using a Map object
val mapDefault = mapOf("ABTest" to "c",
"key2" to "val2",
"key3" to "val3",
"key4" to "val4")
- Using an XML resource file
<?xml version="1.0" encoding="utf-8"?>
<remoteconfig>
<value key="ABTest">c</value>
</remoteconfig>
*/
val agConnectConfig = AGConnectConfig.getInstance()
agConnectConfig.applyDefault(R.xml.remote_config)
remoteButton = findViewById(R.id.remote)
remoteButton?.setOnClickListener {
agConnectConfig.fetch(0).addOnSuccessListener {
agConnectConfig.apply(it)
val abTestResponse = agConnectConfig.getValueAsString("ABTest")
if (abTestResponse == "a"){
showUpdateAlert("abTestResponse = A ")
}
else if(abTestResponse == "b"){
showUpdateAlert("abTestResponse = B ")
}
}.addOnFailureListener {
// fail fetching from remote config
it.printStackTrace()
}
}
}
Finally, you need to start your test on the A/B Testing screen. Sufficient data must be collected to obtain the test result.
I’d like to add the screenshots I took while I was doing the test.
Conclusion
By using these two services, you can diversify your application according to your users, thus increasing the interaction. Moreover, without updating the application.
I hope this article was useful.
References
Remote Configuration
A/B Testing
Nice article
Is huawei AB testing better than google firebase AB testing
riteshchanchal said:
Is huawei AB testing better than google firebase AB testing
Click to expand...
Click to collapse
For me, huawei's is better in some aspects. But I actually suggest you have a try by yourself.

How Can I Quickly Integrate Cloud Functions of AppGallery Connect into My Cocos-based App?

1. Environment
SDK Version:agconnect-storage:1.3.0.300
Platform:Cocos Creator
Device:HUAWEI P40 Pro
AppGallery Connect:
https://developer.huawei.com/consumer/en/service/josp/agc/index.html
2. Enabling and Configuring Cloud Functions in AppGallery Connect
Note: Currently, Cloud Functions is still under beta state. To use the service, you need to send an email for application. For details, check:
https://developer.huawei.com/consum...allery-connect-Guides/agc-cloudfunction-apply
1. Create an app first and add it to a project, or select an app from the project list on the My projects page in AppGallery Connect.
Under the project, go to Build > Cloud Functions, and click Enable now.
2. Create a function based on the description in the following codelab.
https://developer.huawei.com/consumer/en/codelab/CloudFunctions/index.html#4
3. Create an HTTP trigger and save the suffix of the value of Trigger URL in the Details area as the trigger identifier of future client requests.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
3. Integrating the Cloud Functions SDK in Cocos Creator
1. Integrate the SDK.
Official documentation:
https://docs.cocos.com/creator/manual/en/cocos-service/agc-applinking.html
1. On the Service panel of Cocos Creator, find Cloud Functions. Currently, the Cloud Functions SDK supports only the Android platform.
2. Before integrating a service, you need to associate the service with an app. Click Association. In the dialog box that is displayed, click Create. The Cocos console is displayed.
3. On the Cocos console, create a game.
4. Go back to Cocos Creator and create, refresh, or select an association.
5. Return to the Cloud Functions page, and enable the service.
2. Download the JSON file.
1. Go to Project settings in AppGallery Connect and download the latest agconnect-services.json file.
2. Save the downloaded agconnect-services.json file to the settings directory in your Cocos project.
4. Configuring the UI Layout
Configure buttons for triggering a cloud function, obtaining the timeout interval, and setting the timeout interval separately.
5. Cloud Functions Development
1. Initialize Cloud Functions in the start block.
Code:
start () {
this._func = huawei.agc.func.funcService;
},
2. Call Cloud Functions with input parameters.
Code:
callWithParam:function() {
this._func.wrap("testcodelab-$latest").call((err, data) => {
if (err !== null) {
console.log("Cloud Function", `error: ${JSON.stringify(err)}`);
}
console.log("Cloud Function", `result: ${JSON.stringify(data)}`);
}, {
year: "2020",
}
);
},
3. Call Cloud Functions without input parameters.
JavaScript:
callWithoutParam:function() {
this._func.wrap("testcodelab-$latest").call((err, data) => {
if (err !== null) {
console.log("Cloud Function", `error: ${JSON.stringify(err)}`);
}
console.log("Cloud Function", `result: ${JSON.stringify(data)}`);
});
},
4. Obtain and set the timeout interval of a function.
JavaScript:
setTime:function() {
this._func.wrap("testcodelab-$latest").setTimeout(100,3);
console.log("Cloud Function", `setTime: ` + 100);
},
getTime:function() {
let currTime = this._func.wrap("testcodelab-$latest").getTimeout();
console.log("Cloud Function", `currTime: ` + currTime);
},
6. Packaging and Testing
In Cocos Creator, go to Project > Build…, package an Android app, and install it to your device. To verify the functions, click the buttons from top to bottom.
If the following information is displayed in JavaScript logs, the integration is successful.
7. Summary
Cloud Functions allows you to keep all functions and related code on the cloud side. You only need to call the wrap.call method to trigger the functions, which reduces the code amount and package size of your APK package.
For more details, please check:
Cloud Functions development guide:
https://developer.huawei.com/consum...connect-Guides/agc-cloudfunction-introduction
Cocos documentation:
https://docs.cocos.com/creator/manual/en/cocos-service/agc-cloudfunc.html

How Can I Quickly Integrate Remote Configuration to a Web App?

Recently, I found that Remote Configuration of AppGallery Connect now supports the web platform, which I’ve long been waiting for. Previously, it has only been supported on Android, but now it can be applied to web apps. For details about the integration demo, visit GitHub.​
Integration Steps​1. Enable the service.
a) Sign in to AppGallery Connect and create a web app.
b) Enable Remote Configuration.
c) Click New parameter and set parameters.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
2. Integrate the SDK.
a) Run the following command:
Code:
npm install –save @agconnect/remoteconfig
3. Implement the functions.
a) Obtain the local configuration parameters.
Create a local configuration map in the Vue.
Apply the local settings.
JavaScript:
export function applyDefault(map) {
return agconnect.remoteConfig().applyDefault(map);
}
b) Call the fetch API to fetch parameter values from the cloud.
JavaScript:
export async function fetch() {
return agconnect.remoteConfig().fetch().then(() => {
return Promise.resolve();
}).catch((err) => {
return Promise.reject(err);
});
}
c) Apply the parameter values to the local host immediately or upon the next launch.
1. Applying the parameter values immediately:
Call the apply API.
JavaScript:
export function apply() {
return agconnect
.remoteConfig().apply().then((res) => {
return Promise.resolve(res);
}
).catch(error => {
return Promise.reject(error);
});
}
2. Applying the parameter values upon the next launch:
Call the applyLastFetch API to apply the last fetched parameter values.
JavaScript:
// Load configurations.
export function applyLastLoad() {
return agconnect
.remoteConfig().loadLastFetched().then(async (res) => {
if (res) {
await agconnect.remoteConfig().apply(res);
}
return Promise.resolve(res);
}
).catch(error => {
return Promise.reject(error);
});
}
d) Obtain all parameter values from the local host and cloud.
Call the getMergedAll API to obtain all parameter values.
JavaScript:
export function getMergedAll() {
return agconnect.remoteConfig().getMergedAll();
}
e) Call the clearAll API to clear all parameter values.
JavaScript:
export function clearAll() {
agconnect.remoteConfig().clearAll();
}
References:
Demo:
https://github.com/AppGalleryConnect/agc-demos/tree/main/Web/agc-romoteconfig-demo-javascript
Remote Configuration Development Guide:
https://developer.huawei.com/consum...-remoteconfig-web-getstarted-0000001056501223
Well explained, Using remote config can we change UI elements.
What is the basic use of Remote Config in web?
sujith.e said:
Well explained, Using remote config can we change UI elements.
Click to expand...
Click to collapse
yes, that is convenient for developers.
ask011 said:
What is the basic use of Remote Config in web?
Click to expand...
Click to collapse
You can flexibly modify the behavior and appearance of applications by changing cloud parameter values.

Using Huawei App Messaging in Flutter

Huawei AppGallery Connect’s App Messaging service allows you to send targeted, useful in-app messages to your users.
The look and content of messages are completely customisable, and there is a wide range of triggers and filters that can be used to decide who will receive a message and when.
Let's take a look today at how we can set this up to work within a flutter project.
As always we will start with a fresh project but of course, you can just as easily use this guide to build the service into an app you already have!
Installing the Flutter Environment​
Download the Flutter SDK.
Decompress the package to any directory.
Add the Flutter command file to the environment variable.
Download the Flutter and Dart plugins in Android Studio.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Enabling the Service and Creating a Flutter project​Sign in to AppGallery Connect, click My projects, click your project, go to Grow > App Messaging, and click Use now. For more information, please refer to App Messaging.
If you do not have an Android project, create one first.
After completing these steps, you can start creating an in-app message.
Click New in the upper right corner.
Set Name and Description
Set the style and content and click Next.
Select a message type from the Layout drop-down list, and set its style and content. Currently, the Modal, Image, and Banner message types are supported.
Set target users and click Next.
In App, select the name of the app package for which you need to publish the in-app message.
You can click New condition to add a condition for matching target users, which include app version, OS version, language, country/region, audience, and more. Among the types, User attributes are defined under HUAWEI Analytics > Management > User attributes, and Prediction is defined by creating prediction tasks under My projects > Grow > Prediction.
Set the message sending time
Message display is triggered by specific events. App Messaging supports two types of trigger events: preset events and HUAWEI Analytics events.
(Optional) Set conversion events. Before setting a conversion event, you need to toggle it on first, which can be done as follows:
Go to HUAWEI Analytics > Management > Events and toggle Mark as conversion event and Event switch on for the specified event. In addition to the events the SDK collects, you can also create a preset or custom event for event tracking and analysis.
Finally, Click Save or Publish.
Integrating the Service SDK​Add dependencies​Start by creating a Flutter project in Android Studio (or opening one).
Then add the agconnect-services.json file from your AppGallery project to the android/app directory
Within the project level build.gradle file make sure to include the huawei maven repo and add the agcp package as a dependency.
Code:
buildscript {
repositories {
google()
mavenCentral()
maven { url 'https://developer.huawei.com/repo/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.huawei.agconnect:agcp:1.6.2.300'
}
}
Next in your app level build.gradle apply the agconnect plugin as so:
Code:
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.huawei.agconnect'
Then in your pubspec.yaml file add the App Messaging SDK dependency.
Code:
dependencies:
flutter:
sdk: flutter
agconnect_appmessaging: ^1.2.0+300
Displaying an In-App Message​If you choose to display a message using the default message layout, the development process is totally coding-free.
By integrating the SDK as above you are all good to go, your creating message will be displayed as per its filters and triggers.
You can also call APIs provided by the service SDK to customize your in-app message.
Customising the Message Layout​Add the following code to onCreate in MainActivity,
Code:
AGCAppMessagingCustomEventStreamHandler.addCustomView();
so that the service SDK can listen to the corresponding event and apply the customized layout.
Code:
streamSubscriptionDisplay = agconnectAppmessaging.customEvent.listen((event) {
showDialog(context ,event.toString());
agconnectAppmessaging.handleCustomViewMessageEvent
(AppMessagingEventType.onMessageDismiss(AppMessagingDismissTypeConstants.CLICK));
});
Then the message is displayed in your app.
Code:
void _showDialog(BuildContext context, String content) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
key: Key("dialog"),
title: Text("Result"),
content: Text(content),
actions: <Widget>[
FlatButton(
child: new Text("Close"),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
});
}
Testing an In-App Message​App Messaging allows you to test an in-app message before it is published. You need to obtain the Anonymous Application Identifier (AAID) of your test device by adding the following code to your Android app module.
Code:
HmsInstanceId inst = HmsInstanceId.getInstance(this);
Task<AAIDResult> idResult = inst.getAAID();
idResult.addOnSuccessListener(new OnSuccessListener<AAIDResult>() {
@Override
public void onSuccess(AAIDResult aaidResult) {
String aaid = aaidResult.getId();
textView.setText(aaid);
Log.d(TAG, "getAAID success:" + aaid );
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Log.d(TAG, "getAAID failure:" + e);
}
});
Sign in to AppGallery Connect, go to Grow > App Messaging > Messages, find the message that you created, click and select Test in the Operation column.
Click Add test user and enter the AAID
Click Save. Check whether the test message is properly displayed on your test device

Categories

Resources