Overview

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 hints to a game level, or recommend promotions 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.

What You Will Create

In this codelab, you will build an app that integrates App Messaging and is able to display messages in different languages created in AppGallery Connect based on the system language.

What You Will Learn

Development Environment and Skill Requirements

Device Requirements

To integrate App Messaging, you need to complete the following preparations:

If you are using Android Studio, you need to integrate the App Messaging SDK into your Android Studio project before development.

  1. Sign in to AppGallery Connect and click My projects.
  2. Click your project card, and select the app for which you need to enable App Messaging from the app drop-down list on the top.
  3. Go to Project settings > General information. In the App information area, click agconnect-services.json to download it.
  4. Copy the agconnect-services.json file to your app's module directory.
  5. Open the app-level build.gradle file and add the following code to integrate the App Messaging SDK:
    dependencies { // Configure the following addresses: implementation 'com.huawei.agconnect:agconnect-appmessaging:1.6.2.300' }
  6. Click Sync Now to synchronize the configuration.
  1. In AppGallery Connect, click My projects.
  2. Click your project card, and select your app to enable App Messaging from the drop-down list on the top.
  3. Go to Grow > App Messaging and click Use now.
  4. Download the agconnect-services.json file again.
  1. Go to Grow > App Messaging.
  2. Click New.
  3. Set Name and Description.
  4. Set the style and content. In this codelab, set Layout to Banner and other parameters as required. Click Next.
  5. Set target users, set the condition as sending messages by app, and select the package name of the current app.
  6. Add a Language condition and select the first language in which you want messages to be displayed in the app. The following uses simplified Chinese as an example.
  7. Set the sending time as follows. The settings mean that the message will be displayed when your app runs in the foreground or is launched.
  8. Ignore conversion event settings, and click Publish in the upper right corner to publish the message.
  9. Repeat the previous steps to create another message in English. Set other parameters as required for this message in English.

No special layout is required for the codelab. Use the default layout.

  1. Run the Android Studio project to generate an APK and install the APK on the test mobile phone.
  2. Set the device language to simplified Chinese, and launch the app. The message in simplified Chinese will be displayed.
  3. Change the device language to English, and launch the app again. The message in English will be displayed accordingly.

Well done. You have successfully built an app that integrates App Messaging of AppGallery Connect and learned how to integrate the App Messaging SDK and create new messages in AppGallery Connect.

Code copied