Intermediate: Integration of Huawei App Messaging in Xamarin(Android)

Ashish Kumar
5 min readJun 18, 2021

Introduction

Huawei App Messaging provides features to notify active users with messages like popup, image and banner. It helps to improve the business and user engagement on the app. We can implement this feature for Restaurants and Online food Order application to provide some offers and promotions on food or restaurants. We can provide advertisements using Huawei App Messaging to improve business.

It also provides more controls on showing app messages. We can set time, frequency(How many times a day message will be shown) and trigger event (when to show the app message on application like App Launch, App First Open or App in Foreground etc.) from App Gallery to show app messages.

Let us start with the project configuration part:

Step 1: Create an app on App Gallery Connect.

Step 2: Select My projects.

Step 3: Click Add project and create your app.

Step 4: Navigate Grow > App Messaging and click Enable now.

Step 5: Create new Xamarin(Android) project.

Step 6: Change your app package name same as AppGallery app’s package name.

a) Right click on your app in Solution Explorer and select properties.

b) Select Android Manifest on lest side menu.

c) Change your Package name as shown in below image.

Step 7: Generate SHA 256 key.

a) Select Build Type as Release.

b) Right click on your app in Solution Explorer and select Archive.

c) If Archive is successful, click on Distribute button as shown in below image.

d) Select Ad Hoc.

e) Click Add Icon.

f) Enter the details in Create Android Keystore and click on Create button.

g) Double click on your created keystore and you will get your SHA 256 key. Save it.

h) Add the SHA 256 key to App Gallery.

Step 8: Sign the .APK file using the keystore for Release configuration.

a) Right-click on your app in Solution Explorer and select properties.

b) Select Android Packaging Signing and add the Keystore file path and enter details as shown in image.

Step 9: Download agconnect-services.json from App Gallery and add it to Asset folder.

Step 10: Right-click on References> Manage Nuget Packages > Browse and search Huawei.Agconnect.Appmessaging and install it.

Now configuration part done.

Let us start with the implementation part:

Step 1: Create the HmsLazyInputStream.cs which reads agconnect-services.json file.

Step 2: Create XamarinContentProvider.cs to initialize HmsLazyInputStream.cs.

Step 3: Add Internet permission to the AndroidManifest.xml.

Step 4: Create the activity_main.xml for showing the app message information.

Step 5: Initialize app messaging and enable the message display inside activity OnCreate() method.

Step 6: Add the listener for app message events.

MainActivity.cs

Now Implementation part done.

Send App Messages:

Step 1: Sign In on App Gallery Connect.

Step 2: Select My projects.

Step 3: Choose Grow > App Messaging on left side menu and click New button.

Step 4: Set style and content and choose type (popup, image and banner) and click Next.

Step 5: Set the target app for app message.

Step 6: Set time and frequency of app message and click Publish.

Step 7: After publishing the app message will show in below image.

Result

Tips and Tricks

1. Add Huawei.Agconnect.AppMessaging NuGet package.

2. Please use Manifest Merger in .csproj file.

Conclusion

In this article, we have learnt about implementing app message in our application. It helps to improve business and user engagement on the app. We can send popup, banner and image message to the application. It also gives control to show message with specific time interval and events within application.

Reference

App Messaging Service Implementation Xamarin

--

--