[Huawei Developers] shikkerimath:
Overview

In this article, we can learn how to integrate Account Kit, Ads Kit and Site kit in food applications. Account Kit guides you to login through the Huawei sign in button. Ads Kit will advertise on the application. Site Kit guides you to select the places or locations. Mobile apps make our world better and easier customer to prefer comfort and quality instead of quantity.

This article will guide you to show favourite hotels or nearby hotels.

Prerequisites

1. Must have a Huawei Developer Account.

2. Must have a Huawei phone with HMS 4.0.0.300 or later.

3. Must have a laptop or desktop with Android Studio, Jdk 1.8, SDK platform 26 and Gradle 4.6 installed.

Integration Preparations

1. First register as Huawei developer and complete identity verification in Huawei developers website, refer to register a Huawei ID.

2. Create a project in android studio, refer Creating an Android Studio Project.

3. Generate a SHA-256 certificate fingerprint.

4. To generate SHA-256 certificate fingerprint. On right-upper corner of android project click Gradle, choose Project Name > app > Tasks > android, and then click signingReport, as follows.

View attachment 5292145

Note: Project Name depends on the user created name.

5. Create an App in AppGallery Connect.

6. Download the agconnect-services.json file from App information, copy and paste in android Project under app directory, as follows.

View attachment 5292147

7. Enter SHA-256 certificate fingerprint and click , as follows.

View attachment 5292149

Note: Above steps from Step 1 to 7 is common for all Huawei Kits.

8. Click Manage APIs tab and Enable required kits (Account Kit and Site Kit).

View attachment 5292153

9. Add the below maven URL in build.gradle(Project) file under the repositories of buildscript, dependencies and allprojects, refer Add Configuration.

maven { url 'http://developer.huawei.com/repo/' }
classpath 'com.huawei.agconnect:agcp:1.4.1.300'

10. Add the below plugin and dependencies in build.gradle(Module) file.

apply plugin: 'com.huawei.agconnect'

implementation 'com.huawei.agconnect:agconnect-core:1.4.2.300'
implementation 'com.huawei.hms:hwid:5.2.0.300'
implementation 'com.huawei.hms:ads-lite:13.4.40.301'
implementation 'com.huawei.hms:site:5.2.0.300

11. Now Sync the gradle.

12. Add the below permissions in AndroidManifest.xml file.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

Account Kit Overview

Huawei Account Kit provides for developers with simple, secure, and quick sign-in and authorization functions. User is not required to enter accounts, passwords and waiting for authorization. User can click on Sign in with Huawei ID button to quickly and securely sign in to the app. We can implement authorization code sign in use case to login to application.

Signing with Authorization Code

In this method, Account kit allows to sign-in using an ID in authorization code mode. When you click the Huawei ID signing in button, it requires the AccountAuthParams and create a service with authParams, then add startActivityForResult() method in Huawei ID signing in button with service and requestCode.

Find the below code to get this method.

val authParams : AccountAuthParams = AccountAuthParamsHelper(AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM).setAuthorizationCode().createParams()
val service : AccountAuthService = AccountAuthManager.getService(this@MainActivity, authParams)
startActivityForResult(service.signInIntent, 1002)

When the user clicks login with Huawei ID button, the app needs to authorize and login operations from the user.

Find the below code to get the result.

override fun onActivityResult(requestCode: kotlin.Int, resultCode: kotlin.Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == 1002) {
//login success
val authAccountTask = AccountAuthManager.parseAuthResultFromIntent(data)
if (authAccountTask.isSuccessful) {
val authAccount = authAccountTask.result
Toast.makeText(this, "signIn get code success." + authAccount.authorizationCode,
Toast.LENGTH_LONG).show()
} else {
Toast.makeText(this, "signIn get code failed: "+ (authAccountTask.exception as ApiException).statusCode,
Toast.LENGTH_LONG).show()
}
}
}

Add the below code in activity_main.xml

<com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton
android:id="@+id/btn_signin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/Huawei_image"
android:layout_centerHorizontal="true"
android:layout_marginTop="70sp"
android:layout_marginBottom="5dp"
android:background="#3b5998"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:visibility="visible"
app:hwid_button_theme="hwid_button_theme_full_title"
app:hwid_corner_radius="hwid_corner_radius_small" />

Result

View attachment 5292159

Sign Out

Use this service to sign out the user from application.

Find the below code.

val signOutTask = service.signOut()
signOutTask?.addOnSuccessListener {
Toast.makeText(this, "signOut Success", Toast.LENGTH_LONG).show()
}?.addOnFailureListener {
Toast.makeText(this, "signOut fail", Toast.LENGTH_LONG).show()
}

Result

View attachment 5292163

Ads Kits Overview

Huawei Ads provides to developers a wide-ranging capabilities to deliver good quality ads content to users. This is the best way to reach target audience easily and can measure user productivity. It is very useful when we publish a free app and want to earn some money from it.

HMS Ads Kit has 7 types of Ads kits. Now we can implement Banner Ads in this application.

Banner Ads are rectangular ad images located at the top, middle or bottom of an application’s layout. Banner ads are automatically refreshed at intervals. When a user clicks a banner ad, in most cases the user will guide to the advertiser’s page.

Standard Banner Ad Dimensions

The following table lists the standard banner ad dimensions.

Read full article in forum

Tips and Tricks

Make sure you are already registered as Huawei developer.

Enable Account kit and Site kit service in the App Gallery.

Make sure your HMS Core is latest version.

Make sure you have added the agconnect-services.json file to app folder.

Make sure you have added SHA-256 fingerprint without fail.

Make sure all the dependencies are added properly.

Banner ads be can also added programmatically.

Conclusion

In this article, we have learnt integration of Account Kit, Ads Kit and Site Kit in food applications. It will guide you to show favourite hotels or nearby hotels based on the user selection.

I hope you have read this article. If you found it is helpful, please provide likes and comments.

References

Account Kit

Banner Ads Kit

Site Kit

Read full article in forum