Huawei push integration
Newer phones manufactured by Huawei come equipped with Huawei Mobile Services (HMS) - a service used to deliver push instead of Google’s Firebase Cloud Messaging (FCM).
This guide will show you how to set up your Huawei Android integration to send push through Braze and take advantage of all existing Braze features, including segmentation, analytics, Canvas, and more!
Step 1: Register for a Huawei developer account
Before getting started, you’ll need to register and set up a Huawei Developer account. In your Huawei account, go to My Projects > Project Settings > App Information, and take note of the App ID
and App secret
.
Step 2: Create a new Huawei app in the Braze dashboard
In the Braze dashboard, go to Manage Settings, listed under the Settings navigation.
Click + Add App, provide a name (i.e., My Huawei App), select Android
as the platform.
Once your new Braze app has been created, locate the push notification settings and select Huawei
as the push provider. Next, provide your Huawei App ID
and Huawei App Secret
.
Step 3: Integrate the Huawei messaging SDK into your app
Huawei has provided an Android integration codelab detailing integrating the Huawei Messaging Service into your application. Follow those steps to get started.
After completing the codelab, you will need to create a custom Huawei Message Service to obtain push tokens and forward messages to the Braze SDK.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class CustomPushService extends HmsMessageService {
@Override
public void onNewToken(String token) {
super.onNewToken(token);
Braze.getInstance(this.getApplicationContext()).setRegisteredPushToken(token);
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
if (BrazeHuaweiPushHandler.handleHmsRemoteMessageData(this.getApplicationContext(), remoteMessage.getDataOfMap())) {
// Braze has handled the Huawei push notification
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
class CustomPushService: HmsMessageService() {
override fun onNewToken(token: String?) {
super.onNewToken(token)
Braze.getInstance(applicationContext).setRegisteredPushToken(token!!)
}
override fun onMessageReceived(hmsRemoteMessage: RemoteMessage?) {
super.onMessageReceived(hmsRemoteMessage)
if (BrazeHuaweiPushHandler.handleHmsRemoteMessageData(applicationContext, hmsRemoteMessage?.dataOfMap)) {
// Braze has handled the Huawei push notification
}
}
}
After adding your custom push service, add the following to your AndroidManifest.xml
:
1
2
3
4
5
6
7
<service
android:name="package.of.your.CustomPushService"
android:exported="false">
<intent-filter>
<action android:name="com.huawei.push.action.MESSAGING_EVENT" />
</intent-filter>
</service>
Step 4: Send a Huawei push
At this point, you’ve created a new Huawei Android app in the Braze dashboard, configured it with your Huawei developer credentials, and have integrated the Braze and Huawei SDKs into your app.
Next, we can test out the integration by testing a new push campaign in Braze.
Create a new push notification campaign
In the Campaigns page, create a new campaign, and choose Push Notification as your message type.
After you name your campaign, choose Android Push as the push platform.
Next, compose your push campaign with a title and message.
Send a test push
In the Test tab, enter your user ID, which you’ve set in your app using the changeUser(USER_ID_STRING)
method, and click Send Test to send a test push.
At this point, you should receive a test push notification on your Huawei (HMS) device from Braze.
Setting up Huawei segmentation (optional)
Since your Huawei app in the Braze dashboard is built upon the Android push platform, you have the flexibility to send push to all Android users (Firebase Cloud Messaging and Huawei Mobile Services), or you can choose to segment your campaign audience to specific apps.
To send push to only Huawei apps, create a new Segment and select your Huawei App within the Apps section.
Of course, if you want to send the same push to all Android push providers, you can choose not to specify the app which will send to all Android apps configured within the current workspace.
Analytics
Once your campaign has been launched, you will see analytics for your campaign or Canvas aggregated for Android push. See our push user guide for more information on Android push analytics and settings.