Implementation of Push Kit in Unity

Push Kit allows a message that pops up on a mobile device. App publishers can send them at any time. Users do not have to be in the app or using their devices to receive them.

Overview

In this article, I will create a demo game and integrate Huawei Push Kit. User can send and receive game points to other game users through push notification which is powered by Huawei Push Kit.

Service Introduction

Push Kit allows a message that pops up on a mobile device. App publishers can send them at any time. Users do not have to be in the app or using their devices to receive them.

This helps you to maintain closer ties with users and increases user awareness of and engagement with your apps.

Push Kit supports two types of messages.

1. Notification messages:

A notification message is an instant message directly displayed in the notification panel on the user device. The user can tap the notification message to trigger the corresponding action such as opening an app or opening a web page. Notification messages can be displayed in various styles, including the text style, inbox style, button style, and customized style (you can customize small icons, large icons on the right, ringtones, breathing light, and badges). You can customize personalized styles to attract users and improve the message acceptance of users. This greatly improves the daily active user (DAU) of your app.

2. Data messages:

Data messages are processed by your app. After a device receives a data message, the device transfers it to the app instead of directly displaying the message. The app then parses the message and triggers the corresponding action. Push Kit only functions as a channel. You can use the data message to implement functions such as the friend invitation, VoIP call, and voice playing.

Prerequisite

1. Unity Engine (Installed in the system)

2. Huawei phone

3. Visual Studio 2019

4. Android SDK & NDK (Build and Run)

Integration process

1. Sign In and Create or Choose a project on AppGallery Connect portal.

2. Navigate to Project settings and download the configuration file.

3. Enable Push Kit from Manage APIs section.

4. Click Agree the Push service Agreement

5. Select Data storage location

6. Enable Now Push notification

7. Create Notification

Game Development

1. Create a new game in Unity.

2. Now add game components and let us start game development.

3. Download HMS Unity Plugin from below site.

https://github.com/EvilMindDevs/hms-unity-plugin/releases

4. Open Unity Engine and import the downloaded HMS Plugin.

Choose Assets > Import Package> Custom Package

5. Choose Huawei > App Gallery.

6. Provide the AppId and other details from agconnect-service.json file and click configure Manifest.

7. Create Huawei Push Kit based scripts.

I have PushManager.cs file in which integrated Huawei push kit based functionality.

Click on PushManager.cs and open in Visual Studio 2019.

Result

Let us build the apk and install in android device.

Tips and Tricks

1. HMS plugin v1.2.0 supports 7 kits.

2. Ensure that you have installed HMS Core (APK) 3.0.0.300 or later.

3. Due to Android API restrictions, Huawei phones running earlier EMUI versions and non-Huawei phones, which are sold outside the Chinese mainland can use Push Kit only when Android API level 21 (Android 5.0) or later is used.

4. The Push Kit server allows a maximum of 1,000 tokens for sending messages at a time. If more tokens need to be used, your app server will have to send messages in batches

Conclusion

In this article, we have learned how to integrate Huawei Push Kit in Unity-based Game.

User can send game points as rewards to other game’s user via push notification.

Thanks for reading this article. Be sure to like and comments to this article if you found it helpful. It means a lot to me.

References

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/service-introduction-0000001050040060

Android Developer