[Huawei Developers] Hakki Ozer:
Huawei App Messaging Service Part2

*Now, you need to set sending time parameters like started and ended time also trigger event time

​

*Ignore the conversion event configuration. Now, click Save in the upper side to save the configurations.

​

Developing App Messaging

We can create a layout for the main page using the code below.

("https://gist.githubusercontent.com/hakki2391/78cdd988dae0ffc6910aa0a257d47790/raw/d8e45fbd33f8be1050d456393f015dd6708b3bdc/xml")

Then, we need to initialize the AGConnectAppMessaging instance using the lines below.

("https://gist.githubusercontent.com/hakki2391/83a44247a75ab4cdec5d38d53860aa28/raw/355e5fbc64fb4fc4a0812d2945edf3ae3a26e2fc/AGConnectAppMessaging")

We need to obtain the device AAID and generate it in the TextView of the project for subsequent testing using code part below.

("https://gist.githubusercontent.com/hakki2391/97b9cb489a3030443f53b5a45b69e321/raw/7a4383cfb72d0816ed6908000c69648ff65092a4/AAID")

On this point, we need to set the flag for forcibly requesting message data from the AppGallery Connect server so that data can be obtained in real time during testing.

("https://gist.githubusercontent.com/hakki2391/8efa94934b1613f9c082b68b6a0d498b/raw/2f150abbb558465f8f801a82f553a7384ef9bc76/gistfile1.txt")

Now, we need to set the pop-up message layout. Different messages are displayed for the tap and closing events.

("https://gist.githubusercontent.com/hakki2391/a2f463f7f3d3b16304fdc581032f5cd7/raw/a3ca27c60a7eb192a10627466b8aeebf565057ef/gistfile1.txt")

Then we will set the button tap event for applying the custom layout.

("https://gist.githubusercontent.com/hakki2391/309ad98ffa22942b53ed5d6cfae14dec/raw/8a9b969313dcbdb470f0a9a45f522e268e78593f/gistfile1.txt")

Now, we will set the button tap event for canceling the custom layout.

("https://gist.githubusercontent.com/hakki2391/0cbc31fb868c05fc5631742d7f983da1/raw/ec1ecb2be2759e3fda7d4419e4e9d7b1d1d2db6e/gistfile1.txt")

In this point, we can customize the layout like below.

("https://gist.githubusercontent.com/hakki2391/c4502ad5e80338bca3f85510463977bf/raw/28f72e53ceeaa0efe40f2781cea506821ac920ba/gistfile1.txt")

Finally, we can customize the layout file, inherit the AGConnectMessagingDisplay class, and rewrite the displayMessage method to display the layout.

("https://gist.githubusercontent.com/hakki2391/32a1ba37a0b092faf7a7923ec1044d72/raw/9bcc53cedda0419187ec58cd45fe1b517b9678e8/gistfile1.txt")

Lets test the App Messaging Demo

When we run the demo app, we will see the screen below.

​

After that we will select the created message from the message list in the AppGallery Connect and click Test.

​

Now, we need to click Add test user on the screen.

​

On this point, we will enter the AAID of the test mobile phone and save test.

​

If we want to use custom layout, we need to click on Set Custom View in the test mobile phone’s application. We have to repeat steps 3 and 4 and click Save to reset the test mobile phone. Switch the app to the background and then to the foreground after at least a second. The message in custom layout is now displayed.

​

If we want to restore the custom layout to the default layout, we must click Close Custom View and reset the test cell phone. Now we should switch the app to the background and then to the foreground after at least a second. The default layout is displayed.

​

Sample Code for APK

We can find the sample apk code using the link below. We can understand how to use App Messaging clearly.

("https://developer.huawei.com/consumer/en/codelab/AppMessaging/index.html#10")

FAQs

We may find FAQs about App Messaging on the link below.

("https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/agc-appmessage-faq")

Thank you for taking your time and reading my article. Hope to see you in my next forum.xda article.