Skip to main content

Huawei Push Kit#

This is the guide for using Huawei Push Kit to receive notifications from Stream Chat.

Configuring Notifications on the Stream Dashboard#

To be able to receive notifications from Stream, you need to provide your Huawei credentials to Stream.

Go to the Huawei Console, and select the project your app belongs to.

info

If you don't have a Huawei project yet, you'll have to create a new one.

Click on Project settings and navigate to the General information tab. Under App Information, locate the App ID and App secret, and copy them:

Locating your Huawei credentials

Open the Stream Dashboard. Navigate to the Chat Overview page for your app.

Navigating to the Chat Overview page on the Stream Dashboard

Scroll down and enable the Huawei switch. Paste your App ID and App secret, and click Save to confirm your changes.

Setting up your Huawei App ID and App Secret on the Stream Dashboard

With that, you're done setting up on the dashboard. Next, you need to add the client-side integration.

Receiving Notifications in the Client#

Start by adding Huawei to your Android project. You only need to set up the Huawei Push Kit dependencies and add a agconnect-services.json file to your project source directory.

Stream Chat's Android SDK ships an artifact that allows quick integration of Huawei Push Kit messages. Add the following dependency to your app's build.gradle file:

repositories {    maven { url 'https://developer.huawei.com/repo/' }}
dependencies {    implementation "io.getstream:stream-chat-android-pushprovider-huawei:$stream_version"}

Then, add a HuaweiPushDeviceGenerator to your NotificationConfig, and pass that into ChatClient.Builder when initializing the SDK:

val notificationConfig = NotificationConfig(    pushDeviceGenerators = listOf(        HuaweiPushDeviceGenerator(            context = context,            appId = "YOUR HUAWEI APP ID"        )    ))ChatClient.Builder("apiKey", context)    .notifications(notificationConfig)    .build()
caution

ChatClient must be initialized before handling push notifications. We recommend setting it up in your Application class.

That's all you have to do to integrate the Huawei push provider artifact!

Using a Custom Huawei Messaging Service#

The Stream Huawei push provider artifact contains a HuaweiMessagingService implementation that sends new Huawei tokens to Stream and forwards incoming push messages to ChatClient to handle.

If you're using Huawei notifications for other purposes inside your app as well, you will need your own custom service to replace this. Here, you have to call HuaweiMessagingDelegate's registerHuaweiToken and handleRemoteMessage methods, like so:

class CustomHuaweiMessagingService : HuaweiMessagingService() {
    override fun onNewToken(token: String) {        // Update device's token on Stream backend        try {            HuaweiMessagingDelegate.registerHuaweiToken(token)        } catch (exception: IllegalStateException) {            // ChatClient was not initialized        }    }
    override fun onMessageReceived(message: RemoteMessage) {        try {            if (HuaweiMessagingDelegate.handleRemoteMessage(message)) {                // RemoteMessage was from Stream and it is already processed            } else {                // RemoteMessage wasn't sent from Stream and it needs to be handled by you            }        } catch (exception: IllegalStateException) {            // ChatClient was not initialized        }    }}
note

Your custom service needs to have an <intent-filter> priority higher than -1 to replace our default service. (This priority is 0 by default.)

Did you find this page helpful?