Huawei Push Kit Integration

TRUETECH is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.
Development and support of all types of mobile applications:
Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1 servicesAll 1735 services
Huawei Push Kit Integration
Medium
~2-3 business days
FAQ
Our competencies:
Development stages
Latest works
  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    756
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    624
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1054
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    947
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    862
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    445

Integrating Huawei Push Kit for Push Notifications

Huawei devices without Google Mobile Services (GMS) — a reality for a significant part of the market: Huawei P40, Mate 30/40/50, Honor after 2020. On these devices FCM doesn't work. Push notification simply won't arrive. If your app targets CIS, China, or markets with high Huawei share — HMS Push Kit integration is mandatory.

Huawei HMS vs Google GMS: architectural choice

Key decision — how to handle both scenarios in one app.

Option 1: Runtime detection. Check on startup whether GMS or HMS available, register in appropriate service:

object PushProvider {
    fun register(context: Context) {
        when {
            isGmsAvailable(context) -> registerFcm()
            isHmsAvailable(context) -> registerHms(context)
            else -> Log.w("Push", "No push service available")
        }
    }

    private fun isGmsAvailable(context: Context): Boolean =
        GoogleApiAvailability.getInstance()
            .isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS

    private fun isHmsAvailable(context: Context): Boolean =
        HuaweiApiAvailability.getInstance()
            .isHuaweiMobileServicesAvailable(context) == ConnectionResult.SUCCESS
}

Option 2: Separate APK / flavor. Gradle productFlavors: gms and hms. Each flavor contains only needed dependencies. Distributed via Google Play (gms) and AppGallery (hms) respectively.

For most projects — option 1 is simpler and supports single APK.

HMS SDK connection

In agconnect-services.json — analog of google-services.json. Downloaded from AppGallery Connect. Placed in app/ directory.

// project build.gradle
classpath 'com.huawei.agconnect:agcp:1.9.1.301'

// app build.gradle
apply plugin: 'com.huawei.agconnect'

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

Message handling service

class HmsPushService : HmsMessageService() {

    override fun onNewToken(token: String?) {
        token ?: return
        ApiClient.registerHmsToken(token, provider = "HMS")
    }

    override fun onMessageReceived(message: RemoteMessage?) {
        message ?: return
        val data = message.dataOfMap
        val title = data["title"] ?: return
        val body = data["body"] ?: return
        NotificationHelper.show(applicationContext, title, body, data)
    }
}

Register in AndroidManifest.xml:

<service
    android:name=".HmsPushService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.huawei.push.action.MESSAGING_EVENT" />
    </intent-filter>
</service>

Getting token manually

// Asynchronously via Task API
HmsInstanceId.getInstance(context).getToken(APP_ID, HmsMessaging.DEFAULT_TOKEN_SCOPE)
    .addOnSuccessListener { token ->
        ApiClient.registerHmsToken(token, provider = "HMS")
    }
    .addOnFailureListener { e ->
        Log.e("HMS", "Get token failed: ${e.message}")
    }

APP_ID — taken from agconnect-services.json. HMS and FCM tokens — different. Server must store provider along with token.

Server sending via HMS REST API

Endpoint: https://push-api.cloud.huawei.com/v1/{appId}/messages:send

{
  "message": {
    "data": "{\"title\":\"New message\",\"body\":\"Ivan wrote to you\"}",
    "token": ["hms_device_token_here"],
    "android": {
      "notification": {
        "title": "New message",
        "body": "Ivan wrote to you",
        "click_action": {
          "type": 1,
          "intent": "myapp://message?id=123"
        }
      }
    }
  }
}

Authentication — OAuth2 Bearer token, obtained via https://oauth-login.cloud.huawei.com/oauth2/v3/token with client_id and client_secret from AppGallery Connect. Token lives 1 hour.

FCM and HMS comparison

Parameter FCM HMS Push Kit
Devices All Android with GMS Huawei/Honor without GMS
SDK com.google.firebase:firebase-messaging com.huawei.hms:push
Config google-services.json agconnect-services.json
REST API Firebase Admin SDK HMS REST + OAuth2
Topics Yes Yes (HMS Topics)
Silent push content_available: true foreground_show: false

Testing

To test HMS, you need physical Huawei device without GMS or emulator from Huawei DevEco Studio. AppGallery Connect → Push Kit → Test has built-in interface for sending test push to specific token.

What's included

  • Registration in AppGallery Connect, Push Kit setup
  • agconnect-services.json and HMS SDK connection
  • HmsMessageService with data-message handling
  • Runtime GMS/HMS detection and registration in appropriate service
  • Token update on server with provider indication
  • Server sending via HMS REST API (or integration with provider like OneSignal)
  • Testing on physical HMS device

Timeline

Basic HMS Push Kit integration: 1 day. With runtime GMS/HMS detection, full token lifecycle, and server-side sending: 2 days.