Integration of Huawei Account Kit ( In Kritify Application)
HMS core (Huawei Mobile Services) opens a wide range of services to application developers. It offers basic services such as logging in with Huawei ID, payment services and push notifications. In addition, HMS core provides various advanced features, such as, positioning, map, machine learning, and games that provide a better experience to Huawei users.
In order to provide a better mobile platform for promoting the business entities in one place such as hotels, restaurants, or clothing stores we, Team SYsters came up with Kritify mobile application. Kritify is a social media platform that hosts all your reviews about business entities in one place! Whether it’s a hotel, restaurant, or clothing store you visited, click a photo, tag the place and post it with a review, thus helping others find places that suit them, promoting the place, and the fun part is you can earn rewards for posting the reviews.
In Kritify, we have integrated two HMS kits so far.
- Account kit
- Map kit
In this part, I will only focus on the Account kit and its implementation.
Account Kit Overview
Using Huawei Account Kit, users can quickly and securely sign in to the application, and the first-time user needs to authorize the application and then, the user has the ability to sign in to the app with one tap using Huawei ID. Huawei facilitates app developers to use the Account Kit on multiple device types such as phones, tablets, and smart screens.
Use case and Demo
Here, the Account kit was used to log into the system and the Huawei ID was used to identify the particular user. Based on the user ID, users have the ability to view the points of each registered site that they have earned by posting the reviews.
The below figures show the login screen with Huawei ID and the earned points of the user for the respective site name.
1. Must have a Huawei Developer Account.
2. Must have a Huawei phone with HMS 22.214.171.1240 or later
3. Must have a laptop or desktop with Android Studio 4.2 or later, JDK 1.8, SDK platform 26, and Gradle 4.6 installed.
In this section, let’s see how to integrate the Huawei Account Kit step by step.
Step 1: Create a project in Android studio.
Step 2: Create a project in AppGallery connect.
Step 3: Generate an SHA-256 certificate fingerprint using the below command.
Step 4: Configure the sign-in certificate fingerprint.
Step 5: Provide the SHA Key and App Package name of the project in the App information section.
Ex — package com.huawei.kritify
Step 6: Provide storage location in the convention section under project settings.
Step 7: Enable Account Kit setting in the Manage APIs section.
Step 8: Download the agconnect-service.json from the App information section and put the JSON file in the app folder of the project.
Step 9: Add the maven URL inside the repositories of buildscript and allprojects respectively (project-level build.gradle file)
Step 10: Add the classpath inside the dependency section of the project-level build.gradle file.
Step 11: Add the plugin in the app-level build.gradle file.
apply plugin: 'com.huawei.agconnect'
Step 12: Add the below library in the app-level build.gradle file dependencies section.
Step 13: Put the below permissions in the AndroidManifest file.
Code — Sign in with an ID
Add the below code in the activity_main.xml file. Using the below code you can get the user interface like in Figure 1.
Add the below code in the MainActivity.java file
- After pressing the Huawei ID sign-in button, it will call the AccountAuthPramsHelper.setIdToken method to send an authorization request.
- After that getService method of AccountAuthManager will be called to initialize the AccountAuthService object.
- Next, it will call the AccountAuthService.getSignInIntent method to display the authorization screen.
- After the authorization is complete the last step is to call the AccountAuthManager.parseAuthResultFromIntent method of onActivityResult to obtain ID information from the sign-in result.
- After a successful sign-in, the app automatically identifies the signed-in ID type based on authAccount.getAccountFlag.
In this article, you saw the main flow to integrate the Huawei Account Kit in your mobile application using Android Studio and Java.
Other than the Account Kit, HMS core provides a wider range of services to enhance the user experience with the Huawei platform.
If you are interested, please find the Kritify app on Huawei App Gallery using the below link.