App Messaging (AGC)
Service Introduction
You can use App Messaging of AppGallery Connect to send relevant messages to target users actively using your app to encourage them to use key app functions. For example, you can send in-app messages to encourage users to subscribe to certain products, provide tips on passing a game level, or recommend activities of a restaurant. App Messaging even allows you to customize how your messages look and the way they will be sent, and define events for triggering message sending to your users at the right moment.
Message Types
Currently, App Messaging supports pop-up, image, and banner messages, which have different content and layouts. You can customize the message content and layout as needed.
A pop-up message can have a title and body and contain an image and up to two buttons. It is a better choice for you to send rich information to your users.
A banner message is displayed on the top of the screen, containing a thumbnail and the message title and body. A user can tap the banner to access the specified page.
An image message only contains an image. For example, an image message can be a poster well designed to promote an activity. A user can tap the image to access the activity details page.
Working Principles
After you integrate the App Messaging SDK into your app, the SDK automatically synchronizes in-app messages published on the AppGallery Connect server and determines whether to display a specific in-app message based on the message's validity period and trigger. A default layout is provided to display an in-app message. You can also call relevant APIs of the App Messaging SDK to customize the message layout for personalized experience. A user can tap an in-app message to access the destination specified during message creation. The App Messaging SDK reports the message display result to AppGallery Connect. You can view the statistics on message displays, taps, and conversion data in AppGallery Connect.
Version Update Description
Developer Guide: How to integrate the App Messaging SDK to your Unity project
Integrating the AppGallery Connect SDK
You must integrate the AppGallery Connect SDK and plug-in before integrating the App Messaging SDK into your app. For details, please refer to AppGallery Connect Quick Start.
Enabling the App Messaging Service
- Sign in to AppGallery Connect and select My projects.
Find your project from the project list and click the app for which you need to enable App Messaging on the project card.
Go to Growing > App Messaging. On the App Messaging page that is displayed, click Enable now.
Note: You may need to set the data storage location when enabling App Messaging. Then, the setting in agconnect-services.json will be automatically updated accordingly. If you have set the data storage location when enabling App Messaging, you need to download the agconnect-services.json file again and integrate it into your project after the service is enabled. For details, please refer to Adding the Configuration File.
- Config the json file
Note: Copy the agconnect-services.json file to the Assets/Plugins/Android folder.
Setting up unity Custom Android manifest and gradle
- Switch platform to android. In player setting
- Enable custom manifest and gradle in player setting. The following is in unity 2019.4 The android struct is after unity 2019.3, manifest and gradle are separated into multiple files.
- Edit -> Project Settings -> Player -> Android(icon) -> other settings -> Identification -> Package Name .The package name is the package name of app in huawei project.
Integrating HUAWEI Analytics Kit
To collect statistics on App Messaging events, you need to use HUAWEI Analytics Kit. Please refer to the https://docs.unity.cn/cn/Packages-cn/com.unity.hms@1.2/manual/
Integrating AppMessage Kit
- Enable and add configurations to project gradle
Edit -> Project Settings -> Player -> Android(icon) -> Publishing Settings -> Build
enable Custom Base Gradle Template
and add the configuration to the Maven repository which path is 'Assets-> Plugins -> Android -> baseProjectTmeplate.gradle'
You will get baseProjectTmeplate.gradle. If unity version is 2019.2 or before, you should add implement and other configuration on MainGradleTemplate.And the repository is:
allprojects {
buildscript {
repositories {
maven { url 'https://developer.huawei.com/repo/' }
}
}
repositories {
maven { url 'https://developer.huawei.com/repo/' }
}
}
- Enable and add configurations to app gradle
Edit -> Project Settings -> Player -> Android(icon) -> Publishing Settings -> Build
enable Custom Launcher Gradle Template
and add build dependencies in launcherTemplate.gradle and the path is ‘Assets-> Plugins -> Android -> LauncherTmeplate.gradle‘
If unity version is 2019.2 or before, you should add implement and other configuration on MainGradleTemplate. To add AppMesasge Kit.
dependencies {
implementation "com.huawei.agconnect:agconnect-appmessaging:1.4.1.300"
}
- Enable and add configurations to base gradle
Edit -> Project Settings -> Player -> Android(icon) -> Publishing Settings -> Build
enable Custom Main Gradle Template
and add build dependencies in mainTemplate.gradle and the path is ‘Assets-> Plugins -> Android -> LauncherTmeplate.gradle‘
If the unity version is 2019.2 or before, you should add implement and other configuration on MainGradleTemplate.
To add AppMesasge Kit.
dependencies {
implementation "com.huawei.agconnect:agconnect-appmessaging:1.4.1.300"
}
- Custom AndroidManifest and add custom Activity.java
Update AndroidManifest for setting app messaging in Assets/Plugins/Android/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN-->
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools">
...
<application>
<activity android:name="com.hms.hms_activity.HmsActivity"
android:theme="@style/UnityThemeSelector">
…
</activity>
...
</application>
</manifest>
Add corresponding Activity.java in Assets/Plugins/Android/HmsActivity.java
package com.hms.hms_activity;
import android.os.Bundle;
import com.huawei.hms.analytics.HiAnalytics;
import com.huawei.hms.analytics.HiAnalyticsTools;
import com.unity3d.player.UnityPlayerActivity;
import com.huawei.agconnect.appmessaging.AGConnectAppMessaging;
import com.huawei.hms.aaid.HmsInstanceId;
public class HmsActivity extends UnityPlayerActivity {
private AGConnectAppMessaging appMessaging;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
HiAnalyticsTools.enableLog();
HiAnalytics.getInstance(this);
appMessaging = AGConnectAppMessaging.getInstance();
appMessaging.setFetchMessageEnable(true);
appMessaging.setDisplayEnable(true);
appMessaging.setForceFetch();
}
}
Demo Project:How to use this demo project?
Create App Message
Enable and disable the corresponding app messaging
After the step “Custom AndroidManifest and add custom Activity.java”, if you add app message in agc, it will be displayed when the application is opened.
Example: force fetch app message
Setting up a scene
5.1 Open a scene:
5.2 Right click and select UI and then you can choose a button:
5.3 Add component to the button and develop a script:
5.4 Edit the script: Double click the script file,and u will open it in VS code
5.5 Defines the code
using HuaweiService; ... public class ... { ... public void ForceFetch() { var appMessaging = AGConnectAppMessaging.getInstance(); appMessaging.setForceFetch(); } ... }
Create a function above
5.6 Bind buttons and interfaces in scripts
Step1. Click “+” to add a function
Step2. Choose a the corresponding scene which has the interface you want to use
Step3. Click the “No Function” select to choose the script and then choose the corresponding function
If there are still things not clear you can check the demo on github. The corresponding appMessaging usage is https://github.com/Unity-Technologies/HuaweiServiceSample/blob/8a72eb9b34a2d6f1cfe3a8d3340dbf2c6ae1eb4b/Assets/HuaweiServiceDemo/Scripts/test/appmessage/AppMessageTest.cs