HOW TO INTEGRATE YOUR ANDROID PROJECT IN HUAWEI PUSH KIT SERVICE FOR SENDING PUSH NOTIFICATIONS

Işılsu ÇİTİM
Huawei Developers
Published in
5 min readJun 30, 2020
Photo by Fotis Fotopoulos on Unsplash

Hello everyone,

Today i’m going to show you how to integrate your project in one of the most powerful service that Huawei has for sending push notifications. But first let’s answer some basic questions about it, shall we :)

-What is HMS Push Kit and why we use it?

HMS is a backend service that provided by HUAWEI for developers. HMS Push Kit is a messaging service which sets up a messaging channel from cloud to devices. Via push kit, developers can send messages to apps on user’s devices in real time including Android, iOS and Web platforms. This helps developers to remain closer ties with users and increases user awareness of the app and engagement. That will help your app to be more intriguing and reduce the possibility of users to delete it.

The benefits of HUAWEI Push Kit have:

● Individual and group messaging, allowing you to send a message to one or more users simultaneously.

● Topic-based or condition-based messaging.

● Messaging to target audiences of HUAWEI Analytics Kit.

● Messaging through the console in AppGallery Connect.

● Messaging after access to the HUAWEI Push Kit server through HTTP.

● Messaging to different users on the same Android device.

● Message caching.

● Real-time message receipt.

● Messaging to Android, iOS, and web apps.

HUAWEI Push Kit supports two types of messages:

● Notification messages:

After a device receives a notification message, the system directly displays it in Notification Center (NC). By tapping the notification message user can open an the app, a web page, or a specific page in the app. The advantages:

-Low power consumption

HUAWEI Push Kit provides NC, which displays notification messages without launching the destination apps. The apps will be launched only when users tap the messages.

-High delivery rate.

When the device battery level is low they are not affected by any power saving plan from being launched.

● Data messages:

These kind of messages are handled by the client app. Instead of displaying the message system transfers it to the app. By that your app can do such actions as:

  • Adding friends
  • Making IP calls.

-How to Add HMS Push Kit into Your Android Project?

First we need to have the essential requirements.

Requirements:

- Configure app information in AppGallery Connect.

- Integrate the HMS SDK.

- Configure the manifest file.

- Configure obfuscation scripts.

1. Configuring App Information in AppGallery Connect

Before you start developing an app, configure app information in AppGallery Connect.

1.1 Registering as a Developer

Before you get started, you must register as a HUAWEI developer and complete identity verification on the HUAWEI Developer website.

1.2 Creating an App

Create an app by referring to Creating an App in AppGallery Connect help center and upload a temporary APK. Set the following parameters as described:

· Package type: APK (Android app) or RPK (quick app)

· Device: Mobile phone

· App category: App or Game

- AppGallery Connect reads the temporary APK to obtain the APK name. Therefore, the temporary APK name must be the same as the released APK name.

1.3 Generating a Signing Certificate Fingerprint

A signing certificate fingerprint is used to verify the authenticity of an app when the app attempts to access HMS Core (APK) through the HMS SDK. Before using HMS Core (APK), you must locally generate a signing certificate fingerprint and configure it in AppGallery Connect.

Please ensure that the following conditions are acquired:

· The JDK has been installed on your PC.

Perform the following steps:

From Gradle on the right section open

My Application -> Tasks -> android -> signingInReport

double click signingInReport and copy SHA-256 fingerprint from console below.

1.4 Configuring the Signing Certificate Fingerprint

1. Sign in to AppGallery Connect and select My apps.

2. Find your app in the list and click the app name.

3. Go to Develop > Overview > App information and set SHA-256 certificate fingerprint to the SHA-256 fingerprint that is generated in the preceding section of Generating a Signing Certificate Fingerprint.

4. After completing configuration, click . The configuration takes effect in about 15 minutes.

1.5 Setting Data Storage Location

To use HUAWEI Push Kit, you must set the data storage location. For details, please refer to Setting Data Storage Location.

If the data storage location is not set, the following functions will be unavailable: topic-based messaging, messaging through the WebPush agent, and messaging to iOS apps.

1.6 Enabling Required Services

· Enable HUAWEI Push Kit.

· Set HUAWEI Push Kit parameters.

2. Integrating the HMS SDK

If you are using Android Studio, you can integrate your HMS SDK by using the Maven repository. Before you start developing an app, integrate the HMS SDK into your Android Studio first.

3. Configuring the Manifest File

After integrating the HMS Core Push SDK of the latest version, register Service under application in the AndroidManifest.xml file so that devices can receive the push token and messages sent by the HUAWEI Push Kit server.

Register DemoHmsMessageService:

Define the DemoHmsMessageService class (the class name is only for reference and can be customized) by extending com.huawei.hms.push.HmsMessageService, and implement its methods.

  • Set exported to false.

4. Configuring Obfuscation Scripts

Configure obfuscation scripts before compiling the APK to prevent the HMS SDK from being obfuscated. If obfuscation arises, the HMS SDK may not function properly.

The configuration file in Android Studio is proguard-rules.pro, and that in Eclipse is proguard-project.txt.

1. Open the obfuscation script file of your project.

2. Add configuration to exclude the HMS SDK from obfuscation.

3. If you have used AndResGuard, add it to the whitelist in the obfuscation script file.

Here is a link for the referance HMS Push Kit Library in my github account if you would like to check out.

That’s it for this article. Hopefully that will help you understand push kit technology better. See you in the next article soon. :)

--

--