You are on page 1of 29

Introduction to HMS Core In-App Messaging Kit

1. An Introduction to HMS In-App Messaging Kit


2. HMS In-App Message Kit Required Settings
3. The Android Code
C O N T E N T S
4. Creating An In-App Message
5. FAQ
6. Some Useful Links
01 An Introduction to HMS In-
App Messaging Kit
An Introduction to HMS In-App Messaging Kit
In-App Messaging of AppGallery Connect is used to send relevant
messages to target users who are actively using our app to encourage
them to use key app functions, or send attractive promotion activities to
enhance user loyalty. In-App Messaging even allows us to customize our
messages, in addition to default message styles. We can also define
events for triggering message sending to our users at the right moment.

For example, you can use this service to send a promotion message of a
course when a user views learning information, improving the course
purchase rate.
Use Case of In-App Messaging Kit

Promoting Key functions of Your App Sending Targeted Messages


We can use In-App Messaging to give a prompt when a user We can send a message to provide users with new
passes a level in a game year gifts.
How HMS In-App Messaging kit works ?
When you integrate the In-App Message 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 once it is triggered by an In-App event, through a layout. In
addition to the default message layout, you can also call relevant APIs of the In-App Messaging
SDK to customize a message layout for personalized experience. During message creation, you
can set the redirection link for a message. Then, a use will be linked to the corresponding
content after tapping the message.

With the help of HUAWEI Analytics, the In-App Messaging SDK is able to report message
display and tap events to AppGallery Connect. You can view the statistics on message displays,
taps, and conversion data in AppGallery Connect for operations decision-making.
02 HMS In-App message Kit
Required Settings
 Create a new app or project in the Huawei app gallery connect.

 Provide the SHA Key and App Package name of the android project in App Information Section.

 Provide storage location in convention section under project setting.

 Enable App Messaging Kit setting in Manage APIs section.

 Navigate to Grow  App Messaging and click on Enable Now button.

 Download the agconnect-services.json from App Information Section. Add the json file in the app
folder of the android project.

 Add maven url inside the repositories of buildscript and allprojects respectively (project build.gradle
file)

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

 Add class path inside the dependency section of project build.gradle file.

classpath 'com.huawei.agconnect:agcp:1.4.1.300'
 Add plugin in the app build.gradle file

apply plugin: 'com.huawei.agconnect‘

 Add library in the app build.gradle file dependencies section.

implementation 'com.huawei.agconnect:agconnect-appmessaging:1.4.2.301'

implementation 'com.huawei.hms:hianalytics:5.1.0.301'

 Put the below permission in AndroidManifest file.

a. INTERNET
b. ACCESS_NETWORK_STATE
c. ACCESS_WIFI_STATE

 Sync the gradle.


03 The Android Code
Anonymous Application Identifier
 We need Anonymous Application Identifier (AAID) for testing purpose.
 This AAID will help us to send In-App Messages to particular device.
 To obtain AAID, you will use getAAID() method.
HmsInstanceId inst = HmsInstanceId.getInstance(this);
Task<AAIDResult> idResult = inst.getAAID();
idResult.addOnSuccessListener(new OnSuccessListener<AAIDResult>() {
@Override
public void onSuccess(AAIDResult aaidResult) {
String aaid = aaidResult.getId();
Log.d(TAG, "getAAID success:" + aaid );
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Log.d(TAG, "getAAID failure:" + e);
}
});
 Need to initialize the AGConnectAppMessaging instance
AGConnectAppMessaging appMessaging = AGConnectAppMessaging.getInstance();

 Need to allow data synchronization from the AppGallery Connect server


appMessaging.setFetchMessageEnable(true);

 Enable message display


appMessaging.setDisplayEnable(true);

 In order to test in-app message, data must be obtained from the AppGallery Connect
server by force. The setForceFetch API can be used only for message testing.
appMessaging.setForceFetch();
04 Creating An In-App
Message
 Sign in to AppGallery Connect and click My projects.
 Find and click your project.
 After selecting your project, you will select App Messaging from the menu. It will look like
this:
 Select New button to create new In-App Message to send to the device.

 Provide the Name and Description.


 Set the style and content, confirm the settings, and click Next.

 Select the message type from the Type drop-down list box. Currently, the following options
are supported:

 Pop-up

 Image

 Banner.
 After providing the details in set style and content section, you will move on to the Image
section. We will provide two image here for portrait and landscape mode of the app.

Remember for portrait the image aspect ratio should be 3:2 (300x200) and
for landscape the image aspect ratio should be either 1:1 (100x100) or 3:2
(300x200)
 We can also provide a button in the Pop-up message. The button contains an action. This
Action contains two option. We can provide user with Disable Message action or redirect user
to particular URL.
 Other parameters required for each message type are described as follows.

Item Pop-up Image Banner


Title Supported Not supported Supported
Message body Supported Not supported Supported
Title text color Supported Not supported Supported
Body text color Supported Not supported Supported
Background color Supported Not supported Supported
Image settings You need to set images for You need to set Image You can set Image
both the portrait and URL for the images. URL for the banner
landscape modes. image.
Button settings You need to set Text, Text Not supported Not supported
color, and Action. You can
select Add secondary
button to set a secondary
button.
Action settings Action options for button Action options for image Action options for banner
tapping: tapping: tapping:
 Disable message  Disable message  Disable message
 Redirect  Redirect  Redirect
 Set the sending target and click Next.

Here you can click New condition to add a condition for matching target users. Conditio
n types include app version, OS version, language, country/region, audience,
user attributes, last interaction, and initial startup.
 The next section is the Set Sending Time section.
 We can schedule a date and time to send message.
 We can also provide an End date and time to stop sending message.
 We can also display message on an events by using trigger event functionality. For example, you can
display a discount of an item in a shopping app. A trigger event is required for each in-app message.
 Also you can flexibly set the frequency for displaying the message.
 The last section is the Set Conversion Event section. This is section is optional

 Click Save in the upper right corner to complete message creation. Also you can click
Preview to preview the display effect of your message on a mobile phone or tablet.

Do not hit the publish button yet. Just save it.


 Now you need test the message in our app. In order to do that you need to find the message
that you need to test, and click Test in the Operation column as it is shown below:

 Click Add test user and enter the AAID of the test device in the text box. Also run the app in
order to find AAID of the test device in the logcat of the Android Studio.
 Publish the message by selecting publish option in the operation column.
 The final result

Pop-up Banner Image


FAQ
Why is an in-app message published on the AppGallery Connect server not displayed on a user's device?

 Check whether the message meets the following display conditions: start time, end time, trigger event
ID, and frequency limit.

 Check whether the device is a test device. A test device synchronizes in-app message data from the
AppGallery Connect server every time a trigger event takes place. Non-test devices perform the
synchronization only once a day and read message data from the local cache for display upon
subsequent trigger events.

 If the device is a non-test device, check whether the in-app message is published after app launch. If so,
the in-app message will be displayed on the next day. In this case, the situation that you encountered is
not a problem.

 If the device is a test device, contact Huawei technical support.


Some Useful Links
Official Document: https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-
Guides/agc-appmessage-introduction-0000001071884501

In-App Message Kit Demo: https://developer.huawei.com/consumer/en/codelab/AppMessaging/index.html#0

In-App Message Kit Article:


https://forums.developer.huawei.com/forumPortal/en/topic/0201246539027590168?fid=0101187876626530
001

https://forums.developer.huawei.com/forumPortal/en/topic/0201321056133360263?fid=0101187876626530
001
Thank You

You might also like