Basavaraj Navi
Posted on February 16, 2022
Introduction
Push notifications offers a great way to increase your application’s user engagement and boost your retention rates by sending meaningful messages or by informing users about your application. These messages can be sent at any time and even if your app is not running at that time. To achieve this you need to follow steps.
Huawei Push Kit is a messaging service developed by Huawei for developers to send messages to apps on users’ device in real time. Push Kit supports two types of messages: notification messages and data messages, which we will cover both in this tutorial. You can send notifications and data messages to your users from your server using the Push Kit APIs or directly from the AppGallery Push Kit Console.
Things required
- Unity Engine must be installed in the system.
- Huawei phone or cloud debugging.
- Visual Studio 2019
- Android SDK & NDK
Steps to integrate
- Sign In and Create or Choose a project on AppGallery Connect portal.
- Navigate to Project settings and download the configuration file.
- Enable Push Kit from Manage APIs section.
- Click Agree the Push service Agreement.
- Select Data storage location.
- Click Enable now Push notification.
- Send Notification from the console.
- Enter all the required details and click on Submit.
Game Development
- Create a new game in Unity.
- Now add game components and let us start game development.
- Download HMS Unity Plugin from below site.
- Open Unity Engine and import the downloaded HMS Plugin. Choose Assets > Import Package> Custom Package
- Choose Huawei > App Gallery.
- Provide the AppId and other details from agconnect-service.json file and click configure Manifest.
- Create Huawei Push Kit based scripts.
using UnityEngine;
namespace HuaweiHms{
public class IPushServiceListener:AndroidJavaProxy{
public IPushServiceListener():base("com.unity.hms.push.IPushService"){}
public virtual void onMessageReceived(RemoteMessage arg0) { }
public void onMessageReceived(AndroidJavaObject arg0) {
onMessageReceived(HmsUtil.GetHmsBase<RemoteMessage>(arg0));
}
public virtual void onMessageSent(string arg0) {
}
public virtual void onNewToken(string arg0) {
}
public virtual void onSendError(string arg0, BaseException arg1) {
}
public void onSendError(string arg0, AndroidJavaObject arg1) {
onSendError(arg0,HmsUtil.GetHmsBase<BaseException>(arg1));
}
public virtual void onTokenError(BaseException arg0) {
}
public void onTokenError(AndroidJavaObject arg0) {
onTokenError(HmsUtil.GetHmsBase<BaseException>(arg0));
}
}
}
Result
Tips and Tricks
- HMS plugin v1.2.0.
- Make sure that you have installed HMS Core.
- The Push Kit server allows a maximum of 1,000 tokens for sending messages at a time.
- If exceed more than 1k it need to be sent batch wise. ## Conclusion In this article, we have learnt what is push service, how to integrate in Unity based game. And also we have learnt that how to send notification from Huawei console to device.
References
Posted on February 16, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.