[Huawei Developers] John Wo:
More information like this, you can visit HUAWEI Developer Forum​

The capability to push messages to users is especially important for improving app engagement. However, it may be difficult to know what users want using conventional push methods, which do not tell you about the status of a user, and as a result, your push messages may fail to attract the attention of users or, even worse, may simply annoy them.

Wouldn't it be good if there was a way to learn about the status of a user in order to push custom content?

HUAWEI Push Kit 5.0 provides scenario-based messaging, which may help you address this pain point. The function identifies user status and displays content that users are interested in at the proper time and in the proper scenarios.

The following uses a demo to describe how to quickly push messages based on specific scenarios. This demo is open source and the source code can be downloaded from

https://github.com/HMS-Core/hms-push-clientdemo-android

1. Development Practice

1. Integrating the HMS Core Push SDK 5.0

1.1 Getting Started

1.1.1 Adding the AppGallery Connect Configuration File of Your App

Download the agconnect-services.json file.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20200813024007.63792982066182956965027475677274:50510817005352:2800:B9A57A75E4D14940870F499D7099859BEF95B654CB99DAB916B802A8FE0E262F.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20200813024007.63792982066182956965027475677274:50510817005352:2800:B9A57A75E4D14940870F499D7099859BEF95B654CB99DAB916B802A8FE0E262F.png[/IMG]

Move the downloaded agconnect-services.json file to the app directory of your Android Studio project.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20200813024021.66783544518024060199104012831936:50510817005352:2800:64F1AEF5D200507BB6C9AFBA84A3396F8E32057714CC17FA334FAD70B2957CB3.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20200813024021.66783544518024060199104012831936:50510817005352:2800:64F1AEF5D200507BB6C9AFBA84A3396F8E32057714CC17FA334FAD70B2957CB3.png[/IMG]

1.2 Configuring the Maven Repository Address for the HMS Core SDK

Open the build.gradle file in the root directory of your Android Studio project.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20200813024121.17418970977737156997667429402451:50510817005352:2800:29362DD7B1D4B97EA680007470DDEF1AE76C55CFC7DD40C98E8BBAE44C095CE9.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20200813024121.17418970977737156997667429402451:50510817005352:2800:29362DD7B1D4B97EA680007470DDEF1AE76C55CFC7DD40C98E8BBAE44C095CE9.png[/IMG]

Add the AppGallery Connect plugin and the Maven repository.

buildscript {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
dependencies {
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
}
}

allprojects {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
}

1.1.3 Adding Build Dependencies

Open the build.gradle file in the app directory.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20200813024339.99908840676944311568519857892434:50510817005352:2800:8F7FEB07A6C4A362B8CA2699A998F57C40D8256327EA83DADEEA896D98DF9479.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20200813024339.99908840676944311568519857892434:50510817005352:2800:8F7FEB07A6C4A362B8CA2699A998F57C40D8256327EA83DADEEA896D98DF9479.png[/IMG]

Add build dependencies in the dependencies section.

dependencies {
implementation 'com.huawei.hms:push:5.0.0.300'
}

Add the following information under apply plugin: 'com.android.application' in the file header:

apply plugin: 'com.huawei.agconnect'

1.1.4 Configuring the AndroidManifest.xml File

Define the DemoHmsMessageService class (the class name is only for reference and can be customized) by inheriting from HmsMessageService, and implement its methods.

android
:name=
".DemoHmsMessageService"

android
:exported=
"false"
>

android
:name=
"com.huawei.push.action.MESSAGING_EVENT"
/>

1.1.5 Configuring Obfuscation Scripts

Open the obfuscation configuration file proguard-rules.pro of your project.

-ignorewarning -keepattributes *Annotation* -keepattributes Exceptions -keepattributes InnerClasses -keepattributes Signature -keepattributes SourceFile,LineNumberTable -keep class com.hianalytics.android.**{*;} -keep class com.huawei.updatesdk.**{*;} -keep class com.huawei.hms.**{*;}

The preceding describes key integration steps. For more details, please refer to the Push SDK 5.0 development guide, which you can access from the following link:

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/android-config-agc-0000001050170137

Ensure that Push Kit is available before going to the next step.

2. Scenario-based Messaging

The scenarios include:

1. Holidays and weekends

2. Temperature (hot, comfortable, or cold)

3. UV intensity

4. DND canceled

5. Headset inserted or Bluetooth car kit disconnected

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20200813024644.44531752332128964755184713602382:50510817005352:2800:C7C46D73C8CDE134B1D33435F64F873F0778D05675BEEA3FA93CE4E61C96D7EA.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20200813024644.44531752332128964755184713602382:50510817005352:2800:C7C46D73C8CDE134B1D33435F64F873F0778D05675BEEA3FA93CE4E61C96D7EA.png[/IMG]

After completing the basic integration, you only need to add four lines of code and apply for the relevant user permission to implement scenario-based messaging.

· Apply for location permission in the holiday/weekend, UV intensity, and temperature scenarios. In addition, enable location permission for HMS Core and your app.

android
:name=
"android.permission.ACCESS_FINE_LOCATION"
/>

android
:name=
"android.permission.ACCESS_BACKGROUND_LOCATION"
/>

android
:name=
"android.permission.ACCESS_COARSE_LOCATION"
/>

· Apply for Bluetooth permission for headset inserted or Bluetooth car kit disconnected.

android
:name=
"android.permission.BLUETOOTH"
/>

The preceding operations may involve applying for new user permission. You may therefore need to update the privacy statement of your app and add usage description for the new user permission.

The HMS Core and Push Service version requirements for scenario-based messaging are as follows.

[IMG="https://miro.medium.com/max/424/1*HHbUw-AzgkRJDSEk9kUh5g.png"]https://miro.medium.com/max/424/1*HHbUw-AzgkRJDSEk9kUh5g.png[/IMG]

You'll need to perform testing on devices that satisfy the above version requirements.

Once you've completed all of the above, you are now ready to create a task on the Push Kit console.

3. Operations on the Push Kit Console

Step 1: Sign in to AppGallery Connect, select My projects, find your project from the project list, and click the app for which you need to create a task.

Step 2: Go to Project Setting > Growing > Push Kit > Automated notifications(Beta) and click New scenario push task to create a push task.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20200813024742.70441204653759271541620154516361:50510817005352:2800:8A5CD5A28CD364F01200B07828A53AC9CA443570A71403870987243308155C3D.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20200813024742.70441204653759271541620154516361:50510817005352:2800:8A5CD5A28CD364F01200B07828A53AC9CA443570A71403870987243308155C3D.png[/IMG]

Step 3: Set relevant parameters.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20200813024829.42577412481702743564465682292238:50510817005352:2800:6E53E6CD76E9280CC05B62B098436EC540D6FDAADD46CDCE1FB908DCE55E86B3.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20200813024829.42577412481702743564465682292238:50510817005352:2800:6E53E6CD76E9280CC05B62B098436EC540D6FDAADD46CDCE1FB908DCE55E86B3.png[/IMG]

Step 4: Select a scenario.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20200813024903.83815637979367403989676369082109:50510817005352:2800:227E80D4FC1738040F1FE4140E5D2735044945F224404FA903183366F4226D6D.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20200813024903.83815637979367403989676369082109:50510817005352:2800:227E80D4FC1738040F1FE4140E5D2735044945F224404FA903183366F4226D6D.png[/IMG]

Step 5: Click Submit.

After the task is created, the task status changes to Sent, indicating that the task has been delivered to the device.

It takes about 10 minutes to create a scenario-based task. When a scenario triggering condition is met, the message will be displayed on the user device.

4. Display Effect

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20200813025153.19588928841677769199825616654075:50510817005352:2800:A96097984C8822D32A2DEE2FB3B516BD033F456B962EF9A2D45123475B999366.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20200813025153.19588928841677769199825616654075:50510817005352:2800:A96097984C8822D32A2DEE2FB3B516BD033F456B962EF9A2D45123475B999366.gif[/IMG]

In the screenshot above, targeted messaging is implemented based on the headset inserted or Bluetooth car kit disconnected scenario. You are welcome to explore more messaging scenarios to ensure you send your users the proper messages at the proper time and in the proper scenarios.

For more information about HUAWEI Push Kit, visit

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/service-introduction-0000001050040060