QUIZ MANIA GAME Featuring Huawei In App Purchase Kit & Ads Kit

Back in the 90’s, it was a revolutionary to have your own website and putting an advertisement in the website was the only source of revenue. But today as space matures, it’s essential for brands to have a clear strategy to monetize their mobile presence. Some companies charge their users before downloading their apps. Others depend on in-app advertising as their sole revenue stream. But, for a lot of brands, their mobile monetization strategy relies entirely (or some part) on In App Purchase. To summaries, when a customer spends money within a mobile app, that’s an in-app purchase.

To make easier for users to make payments and developers to focus solely on app innovation, Huawei provided us with an extraordinary kit i.e. HMS Core In App Purchase (IAP) Kit.

HMS In App Purchase helps developers in variety of situation to earn revenue such as paying for access to a dating app’s special features, subscribing to a streaming music app’s premium tier, buying more gold bars in games etc.


Today, in this article we are going to see how to integrate HMS In App Purchase in a simple yet complex Quiz Game app. To be honest everything can’t be covered in a single article. So, I have prepared a sample project and uploaded on GitHub soon. I also tried making it simple as much as possible so that every beginner can understand it.

Settings Needed

  1. Provide the SHA Key and App Package name of the android project in App Information Section.
  2. Provide storage location in convention section under project setting.
  3. Enable In-App Purchase setting in Manage APIs section.
  4. After completing all the above points we need to download the agconnect-services.json from App Information Section. Copy and paste the json file in the app folder of the android project.
  5. Copy and paste the below maven url inside the repositories of buildscript and allprojects respectively (project build.gradle file)

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

7. Copy and paste the below class path inside the dependency section of project build.gradle file.

classpath ‘com.huawei.agconnect:agcp:’

8. Copy and paste the below plugin in the app build.gradle file

apply plugin: ‘com.huawei.agconnect’

9. Copy and paste below library in the app build.gradle file dependencies section.

implementation ‘com.huawei.hms:iap:’

10. Put the below permission in AndroidManifest file.

<uses-permission android:name=”android.permission.INTERNET” />
<uses-permission android:name=”android.permission.READ_EXTERNAL_STORAGE” />
<uses-permission android:name=”android.permission.REQUEST_INSTALL_PACKAGES” />
<uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE” />
<uses-permission android:name=”android.permission.ACCESS_WIFI_STATE” />

11. Now Sync the gradle.

Essential Requirement

Become a Merchant


a) Login to Huawei Developer website.

b) Go to console.

c) Under Settings you will find Merchant Service as shown below:

d) Provide our bank details information here as shown below:

e) Provide our tax related information here as shown below:

f) Finally click submit to save the record for verification.

Need Public Key


a) On the Develop tab page, go to Earning > In-App Purchases from the navigation tree on the left and click Settings. If this is the first time we configure the IAP service, a dialog box is displayed for you to sign the agreement.

b) After the configuration is successful, we will be able to see a public key. This public key we will use later.

Need Sandbox Account

We need sandbox account in order to test HMS IAP. During app development and testing, we can test product payments with a test account in the sandbox environment. During the testing period, when a purchase is initiated by the test account, the Huawei IAP server will identify the test account and directly process a successful payment, without real payments made.


a) Go to AGC and select users and permissions.

b) Select Test account as shown below:

c) Click Add button to add test account as shown below:

d) After this a testing account is added. Make sure to add account which is used in Huawei devices to login.

Types of Products In App Purchase


1) Consumables: They are products that are intended to be consumed and purchased repeatedly, such as in-game currencies as shown below:

2) Non-consumables: Users only need to purchase them once. Such products do not expire or decrease as they are used. We can use non-consumable for removing ads in the app as shown below:


Adding Products In App Purchase


a) Select the app which needs In App Purchase in AGC.

b) Go to Operate > Products > Product Management and click Add Product.

c) For Non-Subscription, we can only select either Consumables or Non-Consumables type. After selecting the type we need to provide a unique Product Id, select a Language, provide a Product Name, provide a Description and then Save it. This is how it will look.

d) Now, we need to setup the Product Price. Click View and edit and configure product prices. Set Converted prize (tax included) and click Refresh. Prices in other currencies will be updated accordingly.

e) Finally it will look like this:


a) First we need to add a Subscription Group. In order to do that, we need to go to Subscription groups tab. It will look like this:

b) Click on Add Subscription group and provide the subscription group name.

c) After adding the group, we need to go back to products tab and add click on Add product button (same as Non-Subscription till step a,b and c) and select Auto-renewable subscriptions.

d) The only difference is that we need a subscription period here.

This parameter is displayed only when Type is set to Auto-renewable subscriptions. The system automatically charges for the subscription based on this period. Renewal stops under any of the following scenarios: the user cancels the subscription, the user takes no action to agree to a price increase, or the system fails to collect subscription fees from a user account for five consecutive billing cycles. At present, the following subscription periods are available: 1 week, 1 month, 2 months, 3 months, 6 months, and 1 year.

e) After providing the above details, save it and select View and edit and configure product prices as shown in step d of Non-Subscription.

f) Finally it will look like this:

In App Purchase in a Game

The name of the game is Quiz Mania.


  1. The topics are General Knowledge, Sports, History and General Science.
  2. When player clicks on any topic, it will take user to the quiz section.
  3. On selecting correct answer, user will gain 20 coins and it will be add.
  4. The player gets 3 life that means the player has 3 chance to guess the correct answer of the questions.
  5. If the player exhaust his / her 3 life then the player need to purchase 300 coins to get 3 life and play the game again.
  6. In order to purchase 300 coins, player needs to click on coin icon and it will redirect player to Non-Subscription (Consumables) product where player can purchase the product, gain 300 coins and select life icon in order to add 3 extra life.
  7. The game has two subscription plan (Subscription) i.e. Premium (Silver & Gold) and Diamond. Here Sports and History comes under Premium plan and General Science under Diamond.
  8. Player need to subscribe to Premium in order to play Sports or History quiz and Diamond in order to play General Science. To do that Player needs to click subscribe button (top left corner) and it will redirect player to Subscription Plan.
  9. After purchasing Premium or Diamond plan, player will be able to play the quiz according to their choice of plan.
  10. Player can remove ads from the app by selecting No Ads button (top right corner) and purchase Non-Subscription (Non-Consumables) product. After the purchasing the product, player will not see any ads in the app.

In App Purchase Code






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

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

GitHub Link

For more reference

b) https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/iap-service-introduction-v4

An Android Developer