Expert: Integration of HMS Core Kits in MVVM and RxAndroid based Android App Part-2

Overview

In this article, I will create a Movie Show android application in which I will integrate HMS Core kits such as Huawei ID, Analytics, Huawei Ads and much more.

In this article I will integrate Analytics and Ads kit.

In this series of article I will cover all the kits with real life usages in Movie Show application. This is the part-2 article of this series.

Part-1: https://forums.developer.huawei.com/forumPortal/en/topic/0202684555189490078?fid=0101187876626530001

Huawei Analytics Service Introduction

HUAWEI Analytics Kit predefines rich analytics models to help you clearly understand user behavior and gain in-depth insights into users, products, and content. As such, you can carry out data-driven operations and make strategic decisions about app marketing and product optimization.

Analytics Kit implements the following functions using data collected from apps:

  1. Provides data collection and reporting APIs for collection and reporting of custom events.
  2. Sets up to 25 user attributes.
  3. Supports automatic event collection and session calculation as well as predefined event IDs and parameters.

Huawei Banner Ads

Banner ads are rectangular images that occupy a spot at the top, middle, or bottom within an app’s layout. Banner ads refresh automatically at intervals. When a user taps a banner ad, the user is redirected to the advertiser’s page in most cases.

Prerequisite

  1. Huawei Phone EMUI 3.0 or later.
  2. Non-Huawei phones Android 4.4 or later (API level 19 or higher).
  3. HMS Core APK 4.0.0.300 or later
  4. Android Studio
  5. AppGallery Account

App Gallery Integration process

  1. Sign In and Create or Choose a project on AppGallery Connect portal.
  2. Navigate to Project settings and download the configuration file.​​​​
  3. Navigate to General Information, and then provide Data Storage location.
  4. Navigate to Manage APIs > Huawei Analytics > Checked.
  5. Navigate to Huawei Analytics > Project Overview > Finish.​​​​​​​​​​​​​​​​​​

App Development

  1. Create A New Project.​​​
  2. Configure Project Gradle.

3. Configure App Gradle.

4. Configure AndroidManifest.xml.

5. Create Activity class with XML UI.

Analytics.java:

LoginActivity.java:

activity_login.xml:

App Build Result

Tips and Tricks

Check whether the Logcat log data on the device is reported successfully. If the log contains resultCode: 200, the data is reported successfully. If a report failure occurs, possible causes are as follows:

Cause 1: The tools:node parameter is set to replace (that is, tools:node=replace). As a result, some configurations of your app may conflict with those of the AppGallery Connect SDK, and therefore an error will occur when the AppGallery Connect API is called to obtain the token.

Cause 2: The configuration for excluding Analytics Kit from obfuscation is not added before you build the APK. As a result, an exception occurs during the running of the APK.

Conclusion

In this article, we have learned how to integrate Huawei Analytics and Ads in Android application. After completely read this article user can easily implement ads and analytics in the android based application.

Thanks for reading this article. Be sure to like and comment to this article, if you found it helpful. It means a lot to me.

References

HMS Docs:

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/introduction-0000001050745149

--

--

Android Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store