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.jsonand HMS SDK connection -
HmsMessageServicewith 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.







