Beginner: Huawei App Messaging Unity Game Development
Introduction
You can use App Messaging of AppGallery Connect to subscribe and send relevant messages to target active users of your app to encourage them to use key app functions. For example, you can send in-app messages to encourage users to subscribe certain products, provide tips on passing a game level or recommend activities of a restaurant.
App Messaging allows you to customize our messages look and the way they will be sent, and define events for triggering message sending to your users at the right moment.
AG Connect supports three types of messages as follows:
- Pop-up message
- Image message
- Banner message
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 10.
- A Huawei phone (with the USB cable), which is used for debugging.
Software Requirements
- Java JDK installation package.
- Unity software installed.
- Visual Studio/Code installed.
- HMS Core (APK) 4.X or later.
Follows the steps.
1. Create Unity Project.
- Open unity Hub.
- Click NEW, select 3D, Project Name and Location.
- Click CREATE, as follows:
2. Click Asset Store, search Huawei HMS Core App Services and click Import, as follows.
3. Once import is successful, verify directory in Assets> Huawei HMS Core App Services path, as follows.
4. Choose Edit > Project Settings > Player and edit the required options in Publishing Settings, as follows.
5. Generate a SHA-256 certificate fingerprint.
To generating SHA-256 certificate fingerprint use below command.
6. Download agconnect-services.json and copy and paste to Assets > Plugins > Android, as follows.
7. Choose Project Settings > Player and update package name.
8. Open LauncherTemplate.gradle and add below line.
9. Open AndroidManifest file and add below permissions.
10. Open “baseProjectTemplate.gradle” and add lines, as follows.
11. Open “mainTemplate.gradle” and add lines, as follows.
12. Enable debug mode use in cmd prompt [optional].
13. Configuring project in AGC
14. Create Scripts folder and create a class.
APPMessaging.cs
AndroidManifest.xml
15. Follow the steps, as shown in image:
a. Create empty GameObject.
b. Assign script APPMessaging(as per you script name) to empty GameObject.
16. To build apk and run in device, choose File > Build Settings > Build for apk or Build and Run for run on connected device.
Result
- Sign in to AppGallery Connect and click My projects.
- Find and click your project.
- Navigate to Grow > App Messaging and click New.
Select Name and Description.
Click Test in Operation drop-down.
Enter text in Test user AAID and click Save.
Tips and Tricks
- Always use the latest version of the library.
- Add agconnect-services.json file without fail.
- Add SHA-256 fingerprint without fail.
- Make sure dependencies added in build files.
- Make sure you have enable debug mode.
- Make sure the image url is correct and aspect ratio for Portrait is 3:2 (300x200) and Landscape aspect ratio is 1:1 or 3:2 (100 x100 or 300x200).
Conclusion
In this article, we have learnt to integrate Huawei AppMessaging service into unity game development. AppMessaging provides services sending promotional messages and new updates and also we can target users to promote some products.
Thanks for reading the article, please do likes, comments and your queries or suggestions.
References