Integrating HMS Push Kit in Unity Game Development
By: Shiddalingeshwar M S
Tags: Push Notification, Unity, Hms Core, Hms, Huawei Mobile Service

Integrating HMS Push Kit in Unity Game Development

HUAWEI Push Kit is a messaging service provided by Huawei for developers. It establishes a messaging channel from the cloud to devices. By integrating HUAWEI Push Kit, developers can send messages to apps on users’ devices in real time using ag-connect. This helps developers maintain closer ties with users and increases user awareness and engagement. The following figure shows the process of sending messages from the cloud to a device. Shiddalingeshwar M S Dec 22, 2020·5 min read

Introduction

HUAWEI Push Kit is a messaging service provided by Huawei for developers. It establishes a messaging channel from the cloud to devices. By integrating HUAWEI Push Kit, developers can send messages to apps on users’ devices in real time using ag-connect. This helps developers maintain closer ties with users and increases user awareness and engagement. The following figure shows the process of sending messages from the cloud to a device.

Development Overview

You need to install Unity software and I assume that you have prior knowledge about the Unity and C#.

Hardware Requirements

A computer (desktop or laptop) running Windows 7 or Windows 10.

A Huawei phone (with the USB cable), which is used for debugging.

Software Requirements

Java JDK installation package

Unity software installed

Visual Studio installed

HMS Core (APK) 4.X or later

Integration Preparations

To integrate HUAWEI Push Kit, you must complete the following preparations:

1. Create a project in AppGallery Connect.

2. Create Unity project.

3. Adding Huawei HMS Core App Services to project.

4. Generate a signing certificate.

5. Generate a SHA-256 certificate fingerprint.

6. Configure the signing certificate fingerprint.

7. Download and save the configuration file.

8. Add the AppGallery Connect plug-in and the Maven repository in LaucherTemplate

9. Add the dependencies in MainTemplate.

10. Add dependencies in BaseProjectTemplate.

11. Build and run the application.

12. Result.

13. For more details, refer Preparations for Integrating HUAWEI HMS Core.

1. Create a project in AppGallery Connect.

2. Create Unity project.

3. Adding Huawei HMS Core App Services.

It will add new menu in unity Huawei > AppGallery

Enter the details by referring the agconnect-services.json file.

You can verify the Huawei folder once you added Huawei HMS Core App Services

4. Generate a signing certificate

Click on File > Build Settings under Publishing Settings create new key store and also you need to add Company Name, Product Name and Package Name.

5. Generate a SHA-256 certificate fingerprint

To generating SHA-256 certificate fingerprint use below command after generating signed key store.

keytool -list -v -keystore D:\Unity\projects_unity\file_name.keystore -alias alias_name

6. Configure the signing certificate fingerprint.

7. Download and save the configuration file.

8. Add Maven repository in LaucherTemplate and dependencies

To do this, click File > Build Settings under Publishing Settings enable build scripting as show below.

Open LaucherTemplate add the below plugin and dependencies

apply plugin: 'com.huawei.agconnect' implementation 'com.huawei.agconnect:agconnect-core:1.2.0.300'

implementation 'com.huawei.hms:push:4.0.1.300'

9. Add the dependencies in MainTemplate.

Open MainTemplate add the below code.

implementation 'com.huawei.hms:push:4.0.1.300'

10. Add dependencies in BaseProjectTemplate.

Open BaseProjectTemplate add below code in both build script repositories and all project repositories.

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

11. Build and run the application.

To build and run the project for android first Switch Platform and then choose Build to generate apk or choose Build Run to build and run on real device connected.

Choose File > Build Settings > Build or Build and Run

12. Result

Tips and Tricks

1. Download latest HMS plugin.

2. HMS plugin v1.2.0 supports 7 kits.

3. HMS Unity Plugin v1.1.2 supports 5 kits.

Conclusion

In this article, we have learned to integrate Push Kit in

Unity based game and send push notification from Ag-connect

Console to device directly.

References

https://developer.huawei.com/consumer/en/hms