目录

You need to complete the development of the following services for an AppGalleryKit app.

Service

Mandatory or Optional

(Chinese Mainland)

Mandatory or Optional

(Outside the Chinese Mainland)

Description

Initializing the App

Mandatory

Optional

  • Apps released in the Chinese mainland: Initialize HUAWEI AppGalleryKit upon app startup to collect data and display bulletins.

  • Apps released outside the Chinese mainland: App initialization is optional.

Initializing HUAWEI Analytics

Optional but strongly recommended

Optional

It is recommended that HUAWEI Analytics be initialized upon app launch so that you can collect and analyze app basic data.

Updating the App

Mandatory

Optional

  • Apps released in the Chinese mainland: The update API provided by Huawei must be called upon app launch.

  • Apps released outside the Chinese mainland: It is optional for calling the update API provided by Huawei upon app launch.

Auth Service

Optional but strongly recommended

Optional but strongly recommended

It is recommended that AppGalleryKit apps integrate Auth Service to uniformly manage users signed in with multiple authentication modes, including HUAWEI IDs, WeChat accounts, email accounts, and anonymous accounts, without the hassle of building an authentication system for the apps separately.

Account Kit

Conditionally optional

Optional

  • Apps released in the Chinese mainland: Integrate HUAWEI Account Kit if your app has an account system.

  • Apps released outside the Chinese mainland: Integration with HUAWEI Account Kit is optional.

In-App Purchases

Mandatory

Mandatory

Integrate this service for your AppGalleryKit app.

Out-of-App Purchases

Recommended

Not supported

Integrate this service if your AppGalleryKit app needs to display product information on the app details page. This service now supports only apps released in the Chinese mainland.

Crash

Recommended

Recommended

It is recommended that AppGalleryKit apps integrate Crash to detect and resolve app crashes promptly.

A/B Testing

Recommended

Recommended

It is recommended that AppGalleryKit apps integrate A/B Testing to compare app versions for performance metrics.

Initializing the App

Scenario

When a user taps the app icon to start the app, initialize the app in the background so that statistics about app use can be collected and in-app bulletins can be displayed.

Note:
If your app has a splash ad, initialize your app after the ad ends.

Service Process

  1. The user taps the app icon on the mobile device to start the app.

  2. The app executes its startup program and loads the required resources. The startup program is created by the developer.

  3.  In the startup program, the app calls JosApps.getJosAppsClient method to obtain the JosAppsClient instance.

  4. HMS SDK returns the current JosAppsClient instance of the app.

  5. The app calls JosAppsClient.init to initialize the app.

  6. If an in-app bulletin has been configured on AppGallery Connect, HMS SDK displays the bulletin page to the user.

Notes

Development Procedures

The key steps for achieving this function are as follows:

Call JosApps.getJosAppsClient to initialize the JosAppsClient object and JosAppsClient.init to initialize the app.

When the app is initialized upon startup, signInHuaweiId in getJosAppsClient can be null.

  1. private void init() {
  2.    JosAppsClient appsClient = JosApps.getJosAppsClient(this, null);
  3.    appsClient.init();
  4.    Log.i(TAG, "init success");
  5. }

No result will display after init is called, and no action is required from your app.

Initializing Huawei Analysis

Scenario

HUAWEI Analytics predefines a large number of 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.

AppGalleryKit requires that the HUAWEI Analytics service be initialized after an app is started, in order to collect automatically collected events. Automatically collection events are classified into the following types:

For details about the automatically collected events, see Automatically Collected Event.

Notes

Restrictions on Different Terminal Platforms.

Privacy Statement

As a data processor, HUAWEI Analytics does not proactively collect the personal data of users. The developer needs to determine which personal data should be collected based on the applicable laws and regulations, and protect users' privileges regarding their personal data.

Development Procedure

Initialize HUAWEI Analytics Kit when the app is started.

  1. @Override
  2. protected void onCreate(Bundle savedInstanceState) {
  3.    super.onCreate(savedInstanceState);
  4.    setContentView(R.layout.activity_main);
  5.    //Enable the SDK log.
  6.    HiAnalyticsTools.enableLog();
  7.    HiAnalyticsInstance instance = HiAnalytics.getInstance(this);
  8. }

After being initialized, HUAWEI Analytics Kit automatically collects system events and activity-based screen events. You can conduct basic data analysis by using relevant HUAWEI Analytics functions. For details, please refer to Huawei Analytics User Guide.

If you wish to use more advanced event analysis functions such as defining and reporting present events and custom events, please refer to Huawei Analytics Development Guide。

Updating the App

For details about how to upgrade an app, please refer to Updating the App.

Auth Service

If your app needs to support user sign-in using third-party accounts (such as HUAWEI IDs, WeChat accounts, QQ numbers, and Facebook accounts), email addresses, mobile numbers, and anonymous accounts, you may need to build a user authentication system on your server to centrally manage all these sign-in functions, which costs much in system building and O&M.

That's when Auth Service of AppGallery Connect comes into the picture. With the service, you do not need to purchase any extra server or build an authentication system by yourself. You only need to call Auth Service APIs on your app client to implement functions such as user registration and sign-in. This will greatly shorten the development period and reduce development costs.

Auth Service does not depend on HUAWEI Account Kit. It supports multiple authentication modes, including HUAWEI ID, WeChat, Tencent QQ, Facebook, Weibo, Google, Twitter, email address, mobile number, and anonymous account. You can use it to manage user sign-ins uniformly for apps to be distributed to any app store. In addition, Auth Service is not limited to Huawei devices. It can also run on non-Huawei devices and iOS devices.

You are advised to integrate Auth Service before integrating HUAWEI Account Kit for AppGalleryKit apps. For details, please refer to Auth Service Development Guide.

Huawei Account

You need to integrate the HUAWEI ID service to your AppGalleryKit app. For details, please refer to HUAWEI Account Kit Development Guide.

In-App Product Payment

You need to integrate the HUAWEI IAP service to your AppGalleryKit app. For details, please refer to HUAWEI IAP Development Guide.

Outer-App Product Payment

You can create a product in the Product Management System (PMS) of AppGallery Connect, package the product for marketing, and display the product publicity image, product name, and product description on their app details screen in AppGallery.

Notice:

The function is available only for apps released in the Chinese mainland.

Out-of-app purchase for PMS-managed products supports the following payment modes:

        - Redemption code: You can configure redemption codes in advance in HUAWEI AppGallery Connect. After a user uses a redemption code to purchase a product in AppGallery, Huawei server instructs your server to complete the product delivery.

        - HMS Core: When a user taps to purchase a product in AppGallery, Huawei HMS Core initiates a payment request. After the payment is complete, Huawei server instructs your server to complete the product delivery.

To implement the DeepLink mode, you simply need to set DeepLink when you Configure product Marketing Information. When a user taps to purchase your product, the user will be redirected to the address specified by DeepLink. The subsequent payment and delivery process is the same as that of in-app purchase. For details, please refer to HUAWEI IAP Development Guide. 

In redemption code payment mode, you only need to configure redemption codes by referring to Virtual Product and your delivery address when Managing Product Marketing. No extra coding is required. 

To use HMS Core to initiate payment, you need to develop the direct purchase and missed order query functions. This section describes how to develop these functions.

Prerequisites

You have configured product marketing information by referring to Configuring Product Marketing Information.

Direct Purchase

Receiving a delivery notification:

1. After the direct purchase is successful, Huawei server calls the Delivery Notification API to instruct the developer's server to deliver the product to the user.

Request

  1. POST {Third-party app server url} HTTP/1.1
  2. Content Type : application/json ; charset=UTF-8
  3. {
  4.  "data": {
  5.    "developerId": "234234234",
  6.    "appId": "1231333",
  7.    "orderId": "sdfsfff32324324234234",
  8.    "productNo": "product344",
  9.    "openId": "openId13123",
  10.    "count": 1,
  11.    "ts": 12312313123131123
  12.  },
  13.  "sign": "string"
  14. }

2. Obtain the public key for verifying the order information. For details, please refer to Obtaining the Public Key for Signature Verification.

3. After receiving the delivery notification, verify the sign field in the delivery notification by referring to the Signature Verification Example and return the processing result to Huawei server according to the queried order data.

Response

  1. {
  2.  "error": {
  3.    "errorCode": 0,
  4.    "errorMsg": "string"
  5.  }
  6. }
  7. or
  8. {
  9.    "data": {
  10.    "result": 0
  11.  }
  12. }

4. Deliver the product based on the product ID and user information.

Proactive notification of delivery success

1. Create an API client for accessing Huawei server APIs. For details, please refer to Creating an API Client.

Note:

You need to create the API client only once to call desired APIs.

2. Call the Obtaining a token to obtain the access token used for API client authentication.

3. After the delivery is successful, call the Delivery Success Notification API to send a notification to Huawei server with the access token. Then Huawei server updates the order status as instructed.

Request

  1. {
  2.  "orderId": "string",
  3.  "productNo": "string",
  4.  "openId": "string",
  5.  "status": 0
  6. "ts": 12312313123131123
  7. }

Response

  1. {
  2.  "error": {
  3.    "errorCode": 0,
  4.    "errorMsg": "string"
  5.  }
  6. }
  7. or
  8. {
  9.  "data": {
  10.    "result": 0
  11.  }
  12. }

Querying Missed Orders

If the delivery notification fails for a direct purchase, order missing occurs. In this case, Huawei server marks the order as not delivered. When an app is started, it needs to check whether the current HUAWEI ID has missed orders. If so, the app instructs the developer's server to deliver involved products. After the developer's server successfully delivers products, the developer's server notifies Huawei server of the delivery success. Huawei server then changes the order status to delivered.


1. Call the JosApps.getProductClient method to initialize the ProductClient instance when your app is started.

  1. ProductClient productClient =  JosApps.getProductClient(this);

2. Call the ProductClient.getMissProductOrder method to query missed orders.

Note:

This step is optional and only intends to detect whether a HUAWEI ID has signed in to the current device. Data query with specific data usage purposes will be performed in Step 4.

For a device signed in with a HUAWEI ID, the HMS SDK queries missed order data. If no HUAWEI ID has signed in to the current device, no data will be returned.

  1. productClient.getMissProductOrder(this)
  2.         .addOnSuccessListener(new OnSuccessListener<ProductOrderList>() {
  3.             @Override
  4.             public void onSuccess(ProductOrderList productOrderInfos) {
  5.                 if (productOrderInfos == null) {
  6.                     LogUtil.i("QueryDPSMissProductList", "not have miss product");
  7.                     return;
  8.                 }
  9.                 StringBuffer stringBuffer = new StringBuffer();
  10.                 for (ProductOrderInfo productOrderInfo : productOrderInfos) {
  11.                     stringBuffer
  12.                             .append("TradeId:").append(productOrderInfo.getTradeId()).append("\r\n")
  13.                             .append("ProductNo:").append(productOrderInfo.getProductNo()).append("\r\n")
  14.                             .append("OrderId:").append(productOrderInfo.getOrderId()).append("\r\n")
  15.                             .append("Sign:").append(productOrderInfo.getSign()).append("\r\n")
  16.                             .append("--------------\r\n:");
  17.                 }
  18.                 LogUtil.i("QueryDPSMissProductList", stringBuffer.toString());
  19.             }
  20.         }).addOnFailureListener(new OnFailureListener() {
  21.             @Override
  22.             public void onFailure(Exception e) {
  23.                 if (e instanceof ApiException) {
  24.                     ApiException apiException = (ApiException) e;
  25.                     LogUtil.i("QueryDPSMissProductList", "getMissProductOrder failed:" + apiException.getStatusCode());
  26.                 }
  27.             }
  28.         });

3. Instruct the user to authorize access to your app using his/her HUAWEI ID.

Note:

To improve user experience, it is recommended that you associate users' HUAWEI IDs with your own account system so that users can view orders placed using both HUAWEI IDs and accounts in your system.

4. Call the ProductClient.getMissProductOrder method again to query missed orders.

5. Call the ProductOrderInfo.getSign method to obtain the signature from order information and verify the signatureby the Public Key in the Obtaining the Public Key for Signature Verification . For details how to verify the signature, please refer to Verifying the Signature for Missed Orders.

6. After the signature is verified, instruct the developer's server to deliver involved products to the user. The developer's server sends a delivery success notification to Huawei server. For details, please refer to Delivery Success Notification.

Crash

The Crash service of AppGallery Connect is a lightweight service that can be quickly integrated into your app without coding to implement crash analysis, so you can learn about your app's crash details through the crash report provided by this service in real time. For details, please refer to Crash Development Guide.

A/B Testing

A/B Testing is used for making comparisons. For example, you can create multiple implementation solutions to achieve a specific objective, let some users use solution A and some others use solution B, and then select a proper solution based on user feedback to improve the decision-making efficiency and reduce the decision risks. For details, please refer to A/B Testing Operation Guide.