[Huawei Developers] Freemind R:
More information about this, you can visit HUAWEI Developer Forum

​

Introduction

This article will guide you to use A/B testing in android project. It will provide details to use HMS and GMS.

Steps

1. Create App in Android

2. Configure App in AGC

3. Integrate the SDK in our new Android project

4. Integrate the dependencies

5. Sync project

Procedure

Step1: Create application in android studio.

HMS related dependencies, Add below dependencies in app directory

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

apply plugin:'com.huawei.agconnect'

Add below dependencies in root directory

maven { url 'http://developer.huawei.com/repo/' }

classpath 'com.huawei.agconnect:agcp:1.2.1.301'

GMS related dependencies, Add below dependencies in app directory

implementation 'com.google.android.gms:play-services-analytics:17.0.0'

implementation 'com.google.firebase:firebase-config:19.2.0'

Add below dependencies into root directory

classpath 'com.google.gms:google-services:4.3.3'

Step2: Create MobileCheckService class, using this class you can identify whether the device has HMS or GMS.

class MobileCheckService {

fun isGMSAvailable(context: Context?): Boolean {
if (null != context) {
val result: Int = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context)
if (com.google.android.gms.common.ConnectionResult.SUCCESS === result) {
return true
}
}
return false
}

fun isHMSAvailable(context: Context?): Boolean {
if (null != context) {
val result: Int = HuaweiApiAvailability.getInstance().isHuaweiMobileServicesAvailable(context)
if (com.huawei.hms.api.ConnectionResult.SUCCESS == result) {
return true
}
}
return false
}
}

Step3: Create instance for Mobilecheckservice inside activity class. Inside OnCreate() call checkAvailableMobileService().This method return whether the device has HMS or GMS.

private fun checkAvailableMobileService() {
if (mCheckService.isHMSAvailable(this)) {
Toast.makeText(baseContext, "HMS Mobile", Toast.LENGTH_LONG).show()
configHmsTest()
} else
if (mCheckService.isGMSAvailable(this)) {
Toast.makeText(baseContext, "GMS Mobile", Toast.LENGTH_LONG).show()
configGmsTest()
} else {
Toast.makeText(baseContext, "NO Service", Toast.LENGTH_LONG).show()
}
}

Step4: If the device support HMS, then use AGConnectConfig.

private fun configHmsTest() {
val config = AGConnectConfig.getInstance()
config.applyDefault(R.xml.remote_config_defaults)
config.clearAll()
config.fetch().addOnSuccessListener { configValues ->
config.apply(configValues)
config.mergedAll
var sampleTest = config.getValueAsString("Festive_coupon")
Toast.makeText(baseContext, sampleTest, Toast.LENGTH_LONG).show()
}.addOnFailureListener { Toast.makeText(baseContext, "Fetch Fail", Toast.LENGTH_LONG).show() }
}

Step5: If the device support GMS, then use FirebaseRemoteConfig.

private fun configGmsTest() {
val firebase = FirebaseRemoteConfig.getInstance();
val configSettings = FirebaseRemoteConfigSettings.Builder().build()
firebase.setConfigSettingsAsync(configSettings)
firebase.setDefaultsAsync(R.xml.remote_config_defaults)

firebase.fetch().addOnCompleteListener { configValues ->
if (configValues.isSuccessful) {
firebase.fetchAndActivate()
var name = firebase.getString("Festive_coupon")
Toast.makeText(baseContext, name, Toast.LENGTH_LONG).show()

} else {
Toast.makeText(baseContext, "Failed", Toast.LENGTH_LONG).show()

}
}
}

App Configuration in Firebase:

Note: A/B test is using HMS configuration, refer

https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201248355275100167&fid=0101187876626530001

Step1: To configure app into firebase Open firebase https://console.firebase.google.com/u/0/?pli=1

Step2: Click Add Project and add required information like App Name, package name, SHA-1.

Step3: After configuration is successful, then click A/B Testing in Grow menu.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200710040423.85343884347878597821253938305854:50510722031928:2800:FA205519AC52D55714677A0ACF2A5E5403C456E9C90698182EE1DF17AB3DC3DD.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200710040423.85343884347878597821253938305854:50510722031928:2800:FA205519AC52D55714677A0ACF2A5E5403C456E9C90698182EE1DF17AB3DC3DD.png[/IMG]

To Start A/b testing experiment Click Create experiment button, It will show you list of supported experiments. Using Firebase you can do three experiments.

· Notifications

· Remote Config

· In-App Messaging

Notification: This experiment will use for sending messages to engage the right users at the right moment.

Remote Config: This experiment will use to change app-behavior dynamically and also using server-side configuration parameters.

In-App Messaging: This experiment will use to send different In-App Messages.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200710041949.28856629346144726725217946311735:50510722060747:2800:3F505AB47E30094C71149E25B9150F33CAD85D42722A98245374F20D25F9E6AA.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200710041949.28856629346144726725217946311735:50510722060747:2800:3F505AB47E30094C71149E25B9150F33CAD85D42722A98245374F20D25F9E6AA.png[/IMG]

Step4: Choose AbTesting > Remote Config > Create a Remote Config experiment, provide the required information to test, as follows

Step5: Choose AbTesting > Remote Config > App_Behaviour, following page will display.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200710042304.96384338625074145535640676438673:50510722031928:2800:7E800525DB4A58C5FD8E964E2FA75068A6B0444F93322904D51F35C151E75716.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200710042304.96384338625074145535640676438673:50510722031928:2800:7E800525DB4A58C5FD8E964E2FA75068A6B0444F93322904D51F35C151E75716.png[/IMG]

Step6: Click Start experiment, then start A/B test based on the experiment conditions it will trigger

Step7: After successful completion of experiment, we can get report.

Conclusion:

Using A/B test, you can control the entire experiment from HMS or GMS dashboard, this form of testing will be highly effective for the developers.

Reference:

To know more about firebase console, follow the URL https://firebase.google.com/docs/ab-testing

Share your thoughts on this article, if you are already worked with A/B tests, then you can share your experience on separation between them with us